Do anybody know how exactly aimdirection is calculated?

I have tried for two days:

Code: [Select]

But this is not exact. The bullet misses the point.

AimPos seems to be independent of player's Position. By altering packets, i found out that the player shoots a particular point if (AimPos, AimDir) are specified. Then changing position with former variables i.e. aimpos and aimdir same, still the player shoots the point.

However, if the position is too 'out of range', the player shoots somewhere else.

So the question is how is aim direction calculated, given the position to hit?

Update- Using aiming weapons like 27, using my code hits the target perfectly, the directions being calculated as above. But it hit somewhere when in normal firing (without aiming or right click). It hits near, but not exact.

I have tried for two days:

`function GetAimDir(aimPos, targetPos)`

{

local x,y,z;

local angle = atan2( -(targetPos.x-aimPos.x), targetPos.y-aimPos.y ); //vcmp angle

local alpha=atan2( targetPos.z - aimPos.z, sqrt( pow( targetPos.y - aimPos.y, 2 ) + pow( targetPos.x - aimPos.x , 2 ) ) );

if(angle >0 ) //angle 0 to 3.14

{

//Quadrant can be North West or South West

if(angle <PI/2)

{

//Quadrant is North West

z=angle;

x=0.0;

if( alpha > 0 )

{

y= -PI + alpha;

}else

y= PI + alpha;

}else

{

//Quadrant is South West

z=PI-angle;

x=PI;

y= alpha;

}

}else

{

//Quadrant can be North East or South East

if( angle > -PI/2 )

{

//Quadrant is North East

z= angle;

x= 0.0;

if( alpha > 0 )

{

y= -PI + alpha;

}else

y= PI + alpha;

}else

{

//Quadrant is South East

z= -PI-angle;

x= PI;

y= alpha;

}

}

return Vector(x,y,z);

}

But this is not exact. The bullet misses the point.

AimPos seems to be independent of player's Position. By altering packets, i found out that the player shoots a particular point if (AimPos, AimDir) are specified. Then changing position with former variables i.e. aimpos and aimdir same, still the player shoots the point.

However, if the position is too 'out of range', the player shoots somewhere else.

So the question is how is aim direction calculated, given the position to hit?

Update- Using aiming weapons like 27, using my code hits the target perfectly, the directions being calculated as above. But it hit somewhere when in normal firing (without aiming or right click). It hits near, but not exact.