Hello,

my big problems right now are collision detection and pathfinding for my units in 3D.

Right now I am using one of Dans samples and enhanced it a bit.

My meshes are stored in a class that is based on a TList (here: Engine)

Bolmovable says if the mesh is allowed to move, nRadius if the XSize of the mesh/2.

Works good for some meshes, for others not.

I have some meshes that are not round (like houses) here only the 2D 'circles' are used.


Code:
function TForm1.boundcollide(spriteself: TDJXSprite): boolean;
var i: integer;
    colSpr: TDJXSprite;
    ColPt: TD3DXVector2;
    tmpVec: TD3DXVector2;
    newx,newz: single;
begin
  //Collision with other sprites
  //do not be alarmed by the complexity of the
  //calculations, they are really simple
  //once you take a closer look;)
  for i:=0 to Engine.Count-1 do
  begin
    if &#40;Engine.Sprites&#91;i&#93;<>spriteself&#41; and
    &#40;distance_dbl&#40;spriteself.x,spriteself.z,0,Engine.Sprites&#91;i&#93;.X,Engine.Sprites&#91;i&#93;.Z,0&#41; < Innomsprite&#40;spriteself&#41;.nRadius+Innomsprite&#40;Engine.Sprites&#91;i&#93;&#41;.nRadius&#41;
    then
    begin
      colSpr&#58;=Engine.Sprites&#91;i&#93;;
      ColPt&#58;=D3DXVector2&#40;&#40;spriteself.X+colSpr.X&#41;/2,&#40;spriteself.z+colSpr.z&#41;/2&#41;;
      tmpVec&#58;=D3DXVector2&#40;spriteself.X - colSpr.X,spriteself.z - colSpr.z&#41;;
      D3DXVec2Normalize&#40;tmpVec, tmpVec&#41;;
      if innomsprite&#40;spriteself&#41;.bolmovable then
      begin
        if innomsprite&#40;ColSpr&#41;.bolmovable then
        begin
          newx&#58;=ColPt.x + tmpVec.x * innomsprite&#40;spriteself&#41;.nRadius;
          newz&#58;=ColPt.y + tmpVec.y * innomsprite&#40;spriteself&#41;.nRadius;
          if &#40;spriteself.x<>newx&#41; or &#40;spriteself.z<>newz&#41; then result&#58;=true;
          spriteself.x &#58;=newx;
          spriteself.z &#58;=newz;
        end
        else
        begin
          spriteself.x &#58;= ColSpr.x + tmpVec.x * innomsprite&#40;ColSpr&#41;.nRadius + tmpVec.x * innomsprite&#40;spriteself&#41;.nRadius;
          spriteself.z &#58;= ColSpr.z + tmpVec.y * innomsprite&#40;ColSpr&#41;.nRadius + tmpVec.y * innomsprite&#40;spriteself&#41;.nRadius;
        end;
      end;
      if innomsprite&#40;ColSpr&#41;.bolmovable then
      begin
        if innomsprite&#40;spriteself&#41;.bolmovable then
        begin
          ColSpr.x &#58;= ColPt.x - tmpVec.x * innomsprite&#40;ColSpr&#41;.nRadius;
          ColSpr.z &#58;= ColPt.y - tmpVec.y * innomsprite&#40;ColSpr&#41;.nRadius;
        end
        else
        begin
          ColSpr.x &#58;= spriteself.x - tmpVec.x * innomsprite&#40;spriteself&#41;.nRadius - tmpVec.x * innomsprite&#40;ColSpr&#41;.nRadius;
          ColSpr.z &#58;= spriteself.z - tmpVec.y * innomsprite&#40;spriteself&#41;.nRadius - tmpVec.y * innomsprite&#40;ColSpr&#41;.nRadius;
        end;
      end;
    end;
  end;
end;
I guess to compare the meshes itself is too slow, so maybe if this collision returns true, it could check the meshes then or something? Or perhaps enhance it for rectangles also?

Does somebody have a good (and fast) solution for this matter?

Then pathfinding comes next.

Firle