• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] How to get camera angle
#4
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;

}
Code:
Discord: Marllun#6297
  Reply


Messages In This Thread
How to get camera angle - by Marllun - 2020-11-30, 02:05 PM
RE: How to get camera angle - by Pinch - 2020-11-30, 04:43 PM
RE: How to get camera angle - by Marllun - 2020-12-01, 04:56 AM
RE: How to get camera angle - by Marllun - 2020-12-01, 05:16 AM

Forum Jump: