SetObjectFacingPlayer (seen it before, removed?) - 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: SetObjectFacingPlayer (seen it before, removed?) (
/showthread.php?tid=284110)
SetObjectFacingPlayer (seen it before, removed?) -
Smurf[SMURF] - 18.09.2011
I've seen this one been used before, now it doesn't work.
Anyone know how I can get this function back?
If you have to code for it, please help me out
Re: SetObjectFacingPlayer (seen it before, removed?) -
Backwardsman97 - 18.09.2011
Set the object to face the player or the player to face the object? It could be fairly simple to pretty complex. If it's just the Z angle of the object / player then it's pretty simple. You can get the 2D angle between them and just set it. If you were talking about an object / player that needs to point at another object / player in 3 dimensions, it's harder. I have a few functions lying around though...
Re: SetObjectFacingPlayer (seen it before, removed?) -
Smurf[SMURF] - 18.09.2011
Awesome, I am looking to make an object face a player. (eg: Shark -> Player)
Could you please post the code for it? I don't know how to make it..
Thanks very much
Re: SetObjectFacingPlayer (seen it before, removed?) -
MP2 - 18.09.2011
pawn Код:
stock SetObjectFacePlayer(Float:Px, Float:Py, Float:x, Float:y)
{
new Float: 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);
return floatround(Pa);
}
This is a custom function I made for my own server, let me explain how to use it:
pawn Код:
CreateObject(model, x, y, z, rx, ry, SetObjectFacePlayer(objectx, objecty, playerx, playery)+offset_if_you_need_one);
Doesn't affect rx or ry though. I'd like to have that.