Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. double PredictMovementAim(Actor other, double myShotSpeed)
  2.     {
  3.         double myAngle = self.angle % 360.0;
  4.         double otherSpeed = other.vel.Length();
  5.         double otherAngle;
  6.         //get a (-90, 90) angle and correct it to (0, 360)     
  7.         if(other.vel.x != 0.0 && other.vel.y != 0.0)
  8.         {
  9.             otherAngle = atan(other.vel.y/other.vel.x);
  10.             if(otherAngle >= 0)
  11.             {
  12.                 if(other.vel.y <= 0)
  13.                 {
  14.                     otherAngle = (otherAngle+180)%360;
  15.                 }
  16.             }
  17.             else
  18.             {
  19.                 if(other.vel.y >= 0)
  20.                 {
  21.                     otherAngle = (otherAngle+180)%360;
  22.                 }
  23.                 else
  24.                 {
  25.                     otherAngle = (360+otherAngle)%360;
  26.                 }
  27.             }
  28.         }
  29.         else
  30.         {
  31.             otherAngle = 0; //it really doesn't matter what this is, so long as it's defined. The magnitude is zero
  32.         }
  33.         double component = otherSpeed*cos(otherAngle-(myAngle+90)); //get the perpendicular component
  34.         double aimAngle = acos(myShotSpeed/sqrt((myShotSpeed*myShotSpeed)+(component*component)));
  35.         if(component < 0) //use the sign of the component on the aim angle
  36.             aimAngle = -aimAngle;
  37.         return aimAngle;
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement