toribio

toribio

May 12th, 2009
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. stock Float:GetPlayerTheoreticAngle(playerid)
  2. {
  3.     if(IsPlayerConnected(playerid))
  4.     {
  5.         new Float:sin, Float:dis;
  6.         new Float:x, Float:y, Float:z, Float:angle;
  7.         new Float:xoffset, Float:yoffset, Float:aoffset;
  8.  
  9.         GetPlayerPos(playerid, x, y, z);
  10.  
  11.         dis += (x - ppos[playerid][0]) * (x - ppos[playerid][0]);
  12.         dis += (y - ppos[playerid][1]) * (y - ppos[playerid][1]);
  13.         dis = floatsqroot(dis);
  14.  
  15.         angle = ReturnPlayerAngle(playerid);
  16.  
  17.         xoffset = x > ppos[playerid][0] ? x - ppos[playerid][0] : ppos[playerid][0] - x;
  18.         yoffset = y > ppos[playerid][1] ? y - ppos[playerid][1] : ppos[playerid][1] - y;
  19.  
  20.         if(ppos[playerid][1] > y && ppos[playerid][0] > x)
  21.         {
  22.             sin = asin(xoffset / dis);
  23.             aoffset = ((sin + 90) - (sin * 2)) - (-90);
  24.         }
  25.  
  26.         if(ppos[playerid][1] < y && ppos[playerid][0] > x)
  27.         {
  28.             sin = asin(xoffset / dis);
  29.             aoffset = (sin + 180) - 180;
  30.         }
  31.  
  32.         if(ppos[playerid][1] < y && ppos[playerid][0] < x)
  33.         {
  34.             sin = acos(yoffset / dis);
  35.             aoffset = (sin + 360) - (sin * 2);
  36.         }
  37.  
  38.         if(ppos[playerid][1] > y && ppos[playerid][0] < x)
  39.         {
  40.             sin = asin(xoffset / dis);
  41.             aoffset = sin + 180;
  42.         }
  43.         return aoffset == 0 ? angle : aoffset;
  44.     }
  45.     return 0.0;
  46. }
Add Comment
Please, Sign In to add comment