Help with angle
#1

I was wondering how this arrow to guide the player to position A Certain That I put there, the arrow pointing to the position. Could you help? Pawn Code:

http://pastebin.com/HJ5pwcVX

Thanks to all who can help.
Reply
#2

So you are creating check points and want a arrow in them to point to where to go?
Reply
#3

Quote:
Originally Posted by ToPhrESH
Посмотреть сообщение
So you are creating check points and want a arrow in them to point to where to go?
Yes, if you can help me.
Reply
#4

so you wanna make checkpoints like in a race?
Reply
#5

Код:
#include <a_samp>

new Arrow[MAX_PLAYERS];
new ArrowTimer;

stock Float:AngleBetweenPoints(Float:XA, Float:YA, Float:XB, Float:YB)
{
	new Float:Angle=-(90+(atan2(YA-YB,XA-XB)));// * 180.0 / 3.141592653;
	return Angle;
}

public OnFilterScriptInit()
{
	ArrowTimer=SetTimer("LOL", 300, 1);
	for(new I = 0; I < MAX_PLAYERS; I ++)
	{
		Arrow[I] = CreateObject(1318,0,0,0,0,0,0);
	}
	return 1;
}

public OnFilterScriptExit()
{
	KillTimer(ArrowTimer);
	for(new I = 0; I < MAX_PLAYERS; I ++) DestroyObject(Arrow[I]);
	return 1;
}

forward LOL();	public LOL()
{
	new Float:pX, Float:pY, Float:pZ;
	for(new I = 0; I < MAX_PLAYERS; I ++)
	{
		if(IsPlayerConnected(I))
		{
			GetPlayerPos(I,pX,pY,pZ);
			SetObjectPos(Arrow[I],pX,pY,pZ+1);
			SetObjectRot(Arrow[I],0,90,-90-AngleBetweenPoints(pX,pY,1153.9650,-1770.1655));
		}
	}
	return 1;
}

stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
{
	new Float:DX, Float:DY;
	new Float:angle;
	
	DX = floatabs(floatsub(x2,X));
	DY = floatabs(floatsub(y2,Y));
	
	if (DY == 0.0 || DX == 0.0)
	{
		if(DY == 0 && DX > 0) angle = 0.0;
		else if(DY == 0 && DX < 0) angle = 180.0;
		else if(DY > 0 && DX == 0) angle = 90.0;
		else if(DY < 0 && DX == 0) angle = 270.0;
		else if(DY == 0 && DX == 0) angle = 0.0;
	}
	else
	{
		angle = atan(DX/DY);
		
		if(X > x2 && Y <= y2) angle += 90.0;
		else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
		else if(X < x2 && Y >= y2) angle -= 90.0;
		else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
	}
	return floatadd(angle, 90.0);
}
tested, working.
Reply
#6

Quote:
Originally Posted by Babul
Посмотреть сообщение
Код:
#include <a_samp>

new Arrow[MAX_PLAYERS];
new ArrowTimer;

stock Float:AngleBetweenPoints(Float:XA, Float:YA, Float:XB, Float:YB)
{
	new Float:Angle=-(90+(atan2(YA-YB,XA-XB)));// * 180.0 / 3.141592653;
	return Angle;
}

public OnFilterScriptInit()
{
	ArrowTimer=SetTimer("LOL", 300, 1);
	for(new I = 0; I < MAX_PLAYERS; I ++)
	{
		Arrow[I] = CreateObject(1318,0,0,0,0,0,0);
	}
	return 1;
}

public OnFilterScriptExit()
{
	KillTimer(ArrowTimer);
	for(new I = 0; I < MAX_PLAYERS; I ++) DestroyObject(Arrow[I]);
	return 1;
}

forward LOL();	public LOL()
{
	new Float:pX, Float:pY, Float:pZ;
	for(new I = 0; I < MAX_PLAYERS; I ++)
	{
		if(IsPlayerConnected(I))
		{
			GetPlayerPos(I,pX,pY,pZ);
			SetObjectPos(Arrow[I],pX,pY,pZ+1);
			SetObjectRot(Arrow[I],0,90,-90-AngleBetweenPoints(pX,pY,1153.9650,-1770.1655));
		}
	}
	return 1;
}

stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
{
	new Float:DX, Float:DY;
	new Float:angle;
	
	DX = floatabs(floatsub(x2,X));
	DY = floatabs(floatsub(y2,Y));
	
	if (DY == 0.0 || DX == 0.0)
	{
		if(DY == 0 && DX > 0) angle = 0.0;
		else if(DY == 0 && DX < 0) angle = 180.0;
		else if(DY > 0 && DX == 0) angle = 90.0;
		else if(DY < 0 && DX == 0) angle = 270.0;
		else if(DY == 0 && DX == 0) angle = 0.0;
	}
	else
	{
		angle = atan(DX/DY);
		
		if(X > x2 && Y <= y2) angle += 90.0;
		else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
		else if(X < x2 && Y >= y2) angle -= 90.0;
		else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
	}
	return floatadd(angle, 90.0);
}
tested, working.
Very good! Thanks.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)