Making a player face a button
#1

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
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)