Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Collision detection in 3D for obstacles, sword fighting...

  1. #21

    Collision detection in 3D for obstacles, sword fighting...

    Nice underwear lol

    The guy gets a breast plate armor and trousers, both can be changed, the boots are directly on the mesh and stay. There will be 4 different chars with own textures, special moves and abilities (correct word?).

    So one last Question (I hope):
    This helped me a lot.
    Now it seems to work if I have the monster exactly in front or, and this is the problem exactly in the back :roll:

    Code:
    function TForm1.fightcollide(spriteself: TDJXEngineItem): boolean;
    var i: integer;
        colSpr: TDJXEngineItem;
        ColPt: TD3DXVector2;
        tmpVec: TD3DXVector2;
        ndist,nrot:  Double;
        vdir,v: TD3DXVector3;
        d: single;
    begin
      result:=false;
      //nrot:=degtorad(spriteself.nrotatey);
      nrot:=spriteself.nrotatey;
      vDir := D3DXVector3(cos(nrot),0,sin(nrot));
      for i:=0 to Engine.Count-1 do begin
        ndist:=distance_dbl(spriteself.x,spriteself.z,0,Engine.Sprites[i].X,Engine.Sprites[i].Z,0);
        if &#40;Engine.Sprites&#91;i&#93;<>spriteself&#41;
        and &#40;ndist<Innomsprite&#40;spriteself&#41;.nRadius*2+Innomsprite&#40;Engine.Sprites&#91;i&#93;&#41;.nRadius*2&#41;
        then begin
          colSpr&#58;=Engine.Sprites&#91;i&#93;;
          //Player hits Monster
          if &#40;spriteself.name='spieler'&#41; and &#40;meshplayer&#40;spriteself&#41;.status=schlag1&#41; then begin
            if &#40;colspr.name='innom'&#41; and &#40;meshinnom&#40;colspr&#41;.status<>schmerz&#41; then begin
          	  D3DXVec3Subtract&#40;v,D3DXVector3&#40;colspr.X,colspr.Y,colspr.Z&#41;,D3DXVector3&#40;spriteself.X,spriteself.Y,spriteself.Z&#41;&#41;;
              D3DXVec3Normalize&#40;vdir, vdir &#41;;
              D3DXVec3Normalize&#40;v,v&#41;;
              d&#58;= &#40;v.x * vdir.x&#41; + &#40;v.z * vdir.z&#41;;
              d &#58;= ArcCos&#40;d&#41;;
              if &#40;d < pi/5&#41; or &#40;d > 5*pi/6&#41; then begin //player is in the front area
                meshinnom&#40;colspr&#41;.nanimpos&#58;=0;
                meshinnom&#40;colspr&#41;.status&#58;=schmerz;
                meshinnom&#40;colspr&#41;.hit&#40;meshplayer&#40;spriteself&#41;.nhitpower&#41;;
              end;
            end;
          end;
        end;
      end;
    end;
    Disabling html....done :twisted:

    Thanks a lot guys, this helps me a lot!

    Firle

  2. #22

    Collision detection in 3D for obstacles, sword fighting...

    you "forgot" to check if d is greater than 0. only then the monster is in front of you. if d is negative then it is behind you. look at the first sample from grudizio.

    greetings,
    dirk
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  3. #23

    Collision detection in 3D for obstacles, sword fighting...

    Now I got the idea.

    This will be very cool for straight hit and 'swinging' hit lol.

    Perfect, thanks! (need to write some comments now)

    This helped me a lot, great stuff, thank you both :salute:

  4. #24

    Collision detection in 3D for obstacles, sword fighting...

    Huehnerschaender:

    The third step - checking if object is below or above camera wiev should be changed to this
    Code:
    // CameraXAngle is the rotation angle along X axis
    oy &#58;= v.y*cos&#40;CameraXAngle&#41;;
    //Pascal does not have tangent function
    tan &#58;= sin&#40;CameraViewAngle*0.5&#41; / cos&#40;CameraViewAngle*0.5&#41;;
    
    if &#40;oy < oz*tan&#41; and &#40;oy > -oz*tan&#41; then
     // object is visible
    Now it works if camera looks up or down.

  5. #25

    Collision detection in 3D for obstacles, sword fighting...

    Thanks grudzio.

    I will try it out as soon as possible.

    Btw, my version of pascal (BDS 2005/2006) has a tan function included in math.pas.

    Greetings,
    Dirk
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •