Hello,
yesterday I build a new routine for fighting collisions.
But something is wrong with it, when I am in the radius of the monster, in some position I hit it never, in another position I hit it always no matter how I rotate.
I guess I did something wrong here.
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);
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 (Engine.Sprites[i]<>spriteself)
and (ndist<Innomsprite(spriteself).nRadius*2+Innomsprite(Engine.Sprites[i]).nRadius*2)
then begin
colSpr:=Engine.Sprites[i];
//Player hits Monster
if (spriteself.name='spieler') and (meshplayer(spriteself).status=schlag1) then begin
if (colspr.name='innom') and (meshinnom(colspr).status<>schmerz) then begin
D3DXVec3Subtract(v,D3DXVector3(colspr.X,colspr.Y,colspr.Z),D3DXVector3(spriteself.X,spriteself.Y,spriteself.Z));
d:= (v.x * vdir.x) + (v.z * vdir.z);
d := ArcCos(d);
//if (d <pi> 3*pi/4) then begin //player is in the front area
if (d <pi> 2*pi/3) then begin //player is in the front area
meshinnom(colspr).nanimpos:=0;
meshinnom(colspr).status:=schmerz;
meshinnom(colspr).hit(meshplayer(spriteself).nhitpower);
end;
end;
end;
end;
end;
end;
Player is here spriteself, the monster is here the Engine item ColSpr.
I just changed the angle a bit for testing purposes but still the same, it depends on the position not on the rotation right now.
My rotation is a bit strange. When turning around I decrease it, I start at 0, at around -7 I am rotatet one time etc, at -14 two times.
When I render with -nrotatey-pi/2 for Y Rotation it is alright.
So much to my nrotateY.
Firle
Bookmarks