toribio

toribio

May 12th, 2009
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. Float:GetPlayerTheoreticAngle(i)
  2. {
  3.     new Float:sin;
  4.     new Float:dis;
  5.     new Float:angle2;
  6.     new Float:x,Float:y,Float:z;
  7.     new Float:tmp3;
  8.     new Float:tmp4;
  9.     new Float:MindAngle;
  10.     if(IsPlayerConnected(i)){
  11.         GetPlayerPos(i,x,y,z);
  12.         dis = floatsqroot(floatpower(floatabs(floatsub(x,ppos[i][0])),2)+floatpower(floatabs(floatsub(y,ppos[i][1])),2));
  13.         if(IsPlayerInAnyVehicle(i))GetVehicleZAngle(GetPlayerVehicleID(i), angle2); else GetPlayerFacingAngle(i, angle2);
  14.         if(x>ppos[i][0]){tmp3=x-ppos[i][0];}else{tmp3=ppos[i][0]-x;}
  15.         if(y>ppos[i][1]){tmp4=y-ppos[i][1];}else{tmp4=ppos[i][1]-y;}
  16.         if(ppos[i][1]>y && ppos[i][0]>x){
  17.             sin = asin(tmp3/dis);
  18.             MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
  19.         }
  20.         if(ppos[i][1]<y && ppos[i][0]>x){
  21.             sin = asin(tmp3/dis);
  22.             MindAngle = floatsub(floatadd(sin, 180), 180.0);
  23.         }
  24.         if(ppos[i][1]<y && ppos[i][0]<x){
  25.             sin = acos(tmp4/dis);
  26.             MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
  27.         }
  28.         if(ppos[i][1]>y && ppos[i][0]<x){
  29.             sin = asin(tmp3/dis);
  30.             MindAngle = floatadd(sin, 180);
  31.         }
  32.     }
  33.     if(MindAngle == 0.0){
  34.         return angle2;
  35.     } else
  36.         return MindAngle;
  37. }
Add Comment
Please, Sign In to add comment