Hello,

I need a collision detection for mainly 2 purposes:
- when the player is walking he should not walk 'through' obstacles
- when the player beats I want to know which monster(s) are hit

It is for a 3D kind of medieval RPG Action Game developed with DanJetX.

All my meshes are stored in a Engine based on a TList.

I have a very basic collision detection working a a circle's radius, taken and altered from a sample from Dan:

function TForm1.boundcollide(spriteself: TDJXEngineItem): boolean;
var i: integer;
colSpr: TDJXEngineItem;
ColPt: TD3DXVector2;
tmpVec: TD3DXVector2;
ndist: Double;
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
result:=false;
for i:=0 to Engine.Count-1 do begin
ndist:=distance_dbl(spriteself.x,spriteself.z,0,En gine.Sprites[i].X,Engine.Sprites[i].Z,0);
if (Engine.Sprites[i]<>spriteself) and (ndist<Innomsprite(spriteself).nRadius+Innomsprite (Engine.Sprites[i]).nRadius+1)
then begin
colSpr:=Engine.Sprites[i];
//Player schl?§gt
if (spriteself.name='spieler') and (meshplayer(spriteself).status=schlag1) then begin
if (colspr.name='innom') and (meshinnom(colspr).status<>schmerz) then begin
meshinnom(colspr).nanimpos:=0;
meshinnom(colspr).status:=schmerz;
meshinnom(colspr).hit(meshplayer(spriteself).nhitp ower);
end;
end;
//Innom schl?§gt
if (spriteself.name='innom') and (meshinnom(spriteself).status<>schlag1) and (meshinnom(spriteself).status<>schmerz) then begin
if (colspr.name='bauer') then begin
meshinnom(spriteself).nanimpos:=0;
meshinnom(spriteself).status:=schlag1;
meshbauer(colspr).hit(meshinnom(spriteself).nhitpo wer);
end;
if (colspr.name='spieler') then begin
meshinnom(spriteself).nanimpos:=0;
meshinnom(spriteself).status:=schlag1;
meshplayer(colspr).hit(meshinnom(spriteself).nhitp ower);
end;
end;
if (Engine.Sprites[i]<>spriteself) and (ndist<Innomsprite(spriteself).nRadius+Innomsprite (Engine.Sprites[i]).nRadius)
then begin
result:=true;
colSpr:=Engine.Sprites[i];
ColPt:=D3DXVector2((spriteself.X+colSpr.X)/2,(spriteself.z+colSpr.z)/2);
tmpVec:=D3DXVector2(spriteself.X - colSpr.X,spriteself.z - colSpr.z);
D3DXVec2Normalize(tmpVec, tmpVec);
if innomsprite(spriteself).bolmovable then begin
if innomsprite(ColSpr).bolmovable then begin
spriteself.x:=ColPt.x + tmpVec.x * innomsprite(spriteself).nRadius;
spriteself.z:=ColPt.y + tmpVec.y * innomsprite(spriteself).nRadius;
end
else begin
spriteself.x := ColSpr.x + tmpVec.x * innomsprite(ColSpr).nRadius + tmpVec.x * innomsprite(spriteself).nRadius;
spriteself.z := ColSpr.z + tmpVec.y * innomsprite(ColSpr).nRadius + tmpVec.y * innomsprite(spriteself).nRadius;
end;
end;
end;
{ if innomsprite(ColSpr).bolmovable then begin
if innomsprite(spriteself).bolmovable then begin
ColSpr.x := ColPt.x - tmpVec.x * innomsprite(ColSpr).nRadius;
ColSpr.z := ColPt.y - tmpVec.y * innomsprite(ColSpr).nRadius;
end
else begin
ColSpr.x := spriteself.x - tmpVec.x * innomsprite(spriteself).nRadius - tmpVec.x * innomsprite(ColSpr).nRadius;
ColSpr.z := spriteself.z - tmpVec.y * innomsprite(spriteself).nRadius - tmpVec.y * innomsprite(ColSpr).nRadius;
end;
end; }
exit;
end;
end;
end;
One problem is it only works with circles, so this is bad when it comes to fences and walls etc. So I need another case for rectangle collisions?

The other problem is, 'spieler' means player, 'innom' is the monster, 'bauer' is a villagers and each of them has a nrotatey variable beween -pi and pi which direction the person faces.
Now when many monsters surround the player, one gets hits but not the one in the right direction, it may also be one standing behind the player...

I am not experienced with that, can somebody help me out, how do you guys do this?

Thanks,
Firle