SA-MP Forums Archive
Move player to facing angle ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Move player to facing angle ? (/showthread.php?tid=544060)



Move player to facing angle ? - ignas1125 - 30.10.2014

Hi, I need help, how could I move player to his facing angle ?
so that I would set player position where he is but 4meters more to his facing angle


Re: Move player to facing angle ? - quagga - 30.10.2014

I don't quite understand what you're asking but if you're looking to get the coordinates a certain distance in front of the player's position this function is extremely useful:

Код:
GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance) {

	new Float:a;
	
	GetPlayerPos(playerid, x, y, a);
	GetPlayerFacingAngle(playerid, a);
	
	if (GetPlayerVehicleID(playerid)) {
	
	    GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
	    
	}
	
	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
	
}
Here's an example of how you could use it:

Код:
new Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
GetXYInFrontOfPlayer(playerid, pos[0], pos[1], 4.0);



Re: Move player to facing angle ? - ignas1125 - 30.10.2014

I need that when I do certain thing that player would set pos and that pos would be x,y,z but to the position would be added distance by facing angle.
exemple:
i'm looking to east and then i write /pos and it would set my position to the same one but move little bit where i was looking (face angle)

THANKS! YOUR CODE WORKS PERFECTLY