Similar Angles
#1

Hi!

I have a little problem.

Code:
Код:
new Float:x, Float:y, Float:z;
new Float:angle;

GetObjectRot(obj, x,y,z);
GetVehicleZAngle(vid, angle);


if(??)
{
     GetVehicleDamageStatus(vid, status[0],status[1],status[2],status[3]);
     UpdateVehicleDamageStatus(vid, status[0],status[1],status[2], 0000);
     DestroyDynamicObject(obj);
}
How do I calculate if the angles are similar?

Screen - http://screenshooter.net/101871354/jrxjvlw
Reply
#2

Subtract the angles with a absolute value and check if the result is within a specified tolerance.
Reply
#3

Tested it and it works:

pawn Код:
#define TOLERANCE 45

new Float:x, Float:y, Float:z, Float:angle, Float:a1, Float:a2, Float:a3, Float:a4;
GetObjectRot(obj, x, y, z);
GetVehicleZAngle(vid, angle);
z = floatadd(z, 90.0); if(z >= 360.0) z = floatsub(z, 360.0);
a1 = floatadd(z, TOLERANCE);
a2 = floatsub(z, TOLERANCE); if(a2 < 0.0) floatadd(a2, 360.0);
z = floatadd(z, 180.0); if(z >= 360.0) z = floatsub(z, 360.0);
a3 = floatadd(z, TOLERANCE);
a4 = floatsub(z, TOLERANCE); if(a4 < 0.0) floatadd(a4, 360.0);
if((a2 < angle < a1) || (a4 < angle < a3))
{
    new status[4];
    GetVehicleDamageStatus(vid, status[0],status[1],status[2],status[3]);
    UpdateVehicleDamageStatus(vid, status[0],status[1],status[2], 1111);
}
Reply
#4

Thanks!
This is my code:
Код:
		static i, x;
		i = 0;
		x = 0;
		while(i < MAX_SPIKES && x < SpikesCounter)
		{
		    if(SpikesOBJ[i] != -1)
		    {
				GetDynamicObjectPos(SpikesOBJ[i], vX, vY, vZ);
				if(IsPlayerInRangeOfPoint(playerid, 3.2, vX, vY, vZ))
				{
				    GetDynamicObjectRot(SpikesOBJ[i], vX, vY, vZ);
					GetVehicleZAngle(vid, vX);

					vZ -= 90.0;
					if(vZ < -360) vZ += 360;
					
					vY = vZ - vX;
					vX -= vZ;
					
					if(-60 < vZ < 60 || -60 < vY < 60 || 120 < vZ < 240 || 120 < vY < 240)
					{
					    GetVehicleDamageStatus(vid, status[0],status[1],status[2],status[3]);
					    UpdateVehicleDamageStatus(vid, status[0],status[1],status[2], 1111);
					    DestroyDynamicObject(SpikesOBJ[i]);
	                    SpikesOBJ[i] = -1;
					    SpikesCounter--;
					    break;
					}
				}
				x++;
			}
			i++;
		}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)