open.mp forum
[Pawn] How to get camera angle - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] How to get camera angle (/showthread.php?tid=1395)



How to get camera angle - Marllun - 2020-11-30

I would like to know how to get camera angle. Player camera.


RE: How to get camera angle - Pinch - 2020-11-30

https://open.mp/docs/scripting/functions/GetPlayerCameraPos


RE: How to get camera angle - Marllun - 2020-12-01

(2020-11-30, 04:43 PM)Pinch Wrote: https://open.mp/docs/scripting/functions/GetPlayerCameraPos





Isn't the angle, I would like how to get the angle, this is position.


RE: How to get camera angle - Marllun - 2020-12-01

I found, the codes:

Code:
stock SetPlayerLookAtPos(playerid, Float:pos_x, Float:pos_y)

{

? ? new

? ? Float:w_px,

? ? Float:w_py,

? ? Float: angle;



? ? GetPlayerPos(playerid, w_px, w_py, angle);

? ? angle = floatabs(atan((pos_y-w_py)/(pos_x-w_px)));



? ? if (pos_x <= w_px && pos_y >= w_py)

? ? angle = floatsub(180.0, angle);

? ? else if (pos_x < w_px && pos_y < w_py)

? ? angle = floatadd(angle, 180.0);

? ? else if (pos_x >= w_px && pos_y <= w_py)

? ? angle = floatsub(360.0, angle);

? ?

? ? angle = floatsub(angle, 90.0);



? ? if (angle >= 360.0)//Prevent angle more than at 360?

? ? angle = floatsub(angle, 360.0);

? ?

? ? SetPlayerFacingAngle(playerid, angle);

? ? return 1;

}



stock GetPlayerAngleAtPos(playerid, Float:pos_x, Float:pos_y)

{

? ? new

? ? Float:w_px,

? ? Float:w_py,

? ? Float: angle;



? ? GetPlayerPos(playerid, w_px, w_py, angle);

? ? angle = floatabs(atan((pos_y-w_y)/(pos_x-w_px)));



? ? if (pos_x <= w_px && pos_y >= w_py)

? ? angle = floatsub(180.0, angle);

? ? else if (pos_x < w_px && pos_y < w_py)

? ? angle = floatadd(angle, 180.0);

? ? else if (pos_x >= w_px && pos_y <= w_py)

? ? angle = floatsub(360.0, angle);

? ?

? ? angle = floatsub(angle, 90.0);



? ? if (angle >= 360.0)//Prevent angle more than at 360?

? ? angle = floatsub(angle, 360.0);

? ?

? ? return angle;

}



stock SetPlayerLookAtObject(playerid, objectid)

{

if(!IsPlayerConnected(playerid))

return 0;



? ? new

? ? Float:w_px,

? ? Float:w_py,

? ? Float:w_ox,

? ? Float:w_oy,

? ? Float:w_oz,

? ? Float: angle;



? ? GetPlayerPos(playerid, w_px, w_py, angle);

? ? GetObjectPos(objectid, w_ox, w_oy, w_oz);



? ? angle = floatabs(atan((w_oy-w_py)/(w_ox-w_px)));



? ? if (w_ox <= w_px && w_oy >= w_py)

? ? angle = floatsub(180.0, angle);

? ? else if (w_ox < w_px && w_oy < w_py)

? ? angle = floatadd(angle, 180.0);

? ? else if (w_ox >= w_px && w_oy <= w_py)

? ? angle = floatsub(360.0, angle);

? ?

? ? angle = floatsub(angle, 90.0);



? ? if (angle >= 360.0)//Prevent angle more than at 360?

? ? angle = floatsub(angle, 360.0);

? ?

? ? SetPlayerFacingAngle(playerid, angle);

? ? return 1;

}



stock GetPlayerAngleAtObject(playerid, objectid)

{

if(!IsPlayerConnected(playerid))

return 0;



? ? new

? ? Float:w_px,

? ? Float:w_py,

? ? Float:w_ox,

? ? Float:w_oy,

? ? Float:w_oz,

? ? Float: angle;



? ? GetPlayerPos(playerid, w_px, w_py, angle);

? ? GetObjectPos(objectid, w_ox, w_oy, w_oz);



? ? angle = floatabs(atan((w_oy-w_py)/(w_ox-w_px)));



? ? if (w_ox <= w_px && w_oy >= w_py)

? ? angle = floatsub(180.0, angle);

? ? else if (w_ox < w_px && w_oy < w_py)

? ? angle = floatadd(angle, 180.0);

? ? else if (w_ox >= w_px && w_oy <= w_py)

? ? angle = floatsub(360.0, angle);

? ?

? ? angle = floatsub(angle, 90.0);



? ? if (angle >= 360.0)//Prevent angle more than at 360?

? ? angle = floatsub(angle, 360.0);

? ?

? ? return angle;

}



stock GetPlayerAngleAtObject(playerid, objectid)

{

if(!IsPlayerConnected(playerid))

return 0;



? ? new

? ? Float:w_px,

? ? Float:w_py,

? ? Float:w_ox,

? ? Float:w_oy,

? ? Float:w_oz,

? ? Float: angle;



? ? GetPlayerPos(playerid, w_px, w_py, angle);

? ? GetDynamicObjectPos(objectid, w_ox, w_oy, w_oz);



? ? angle = floatabs(atan((w_oy-w_py)/(w_ox-w_px)));



? ? if (w_ox <= w_px && w_oy >= w_py)

? ? angle = floatsub(180.0, angle);

? ? else if (w_ox < w_px && w_oy < w_py)

? ? angle = floatadd(angle, 180.0);

? ? else if (w_ox >= w_px && w_oy <= w_py)

? ? angle = floatsub(360.0, angle);

? ?

? ? angle = floatsub(angle, 90.0);



? ? if (angle >= 360.0)//Prevent angle more than at 360?

? ? angle = floatsub(angle, 360.0);

? ?

? ? return angle;

}