SA-MP Forums Archive
Making a player face a button - 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: Making a player face a button (/showthread.php?tid=370693)



Making a player face a button - Dodo9655 - 20.08.2012

Hello, I want to make a buttons system (basically a keypad on a wall), how do I make it so when player presses a key, he automatically turns to the button and applies the keypad sliding animation.
What are the calculations I need to do in order to make the player turn the right way, facing the keypad?

Thanks


Re: Making a player face a button - ExTaZZ69 - 16.09.2016

Hi!
Unfortunately, sa-mp doesn't support all keyboard keys detection.
Anyway, you can use this function:
Код:
stock SetPlayerLookAt(playerid, Float:X, Float:Y)
{
	new Float:Px, Float:Py, Float: Pa;
	GetPlayerPos(playerid, Px, Py, Pa);
	Pa = floatabs(atan((Y-Py)/(X-Px)));
	if (X <= Px && Y >= Py) Pa = floatsub(180, Pa);
	else if (X < Px && Y < Py) Pa = floatadd(Pa, 180);
	else if (X >= Px && Y <= Py) Pa = floatsub(360.0, Pa);
	Pa = floatsub(Pa, 90.0);
	if (Pa >= 360.0) Pa = floatsub(Pa, 360.0);
	SetPlayerFacingAngle(playerid, Pa);
}
You have to get all X and Y keys coords.