Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. double PredictMovementAim(Actor other, double myShotSpeed)
  2.     {
  3.         //Determine if we even need to adjust our aim
  4.         if(other.vel.x != 0.0 && other.vel.y != 0.0)
  5.         {
  6.             double myAngle = self.angle % 360.0;
  7.             double otherSpeed = other.vel.Length();
  8.             double vx, vy;
  9.             vx = other.vel.x;
  10.             vy = other.vel.y;
  11.            
  12.             //get a (-90, 90) angle
  13.             double otherAngle = atan(vy/vx);
  14.            
  15.             //correct it to (0, 360) using quadrants
  16.             if(otherAngle >= 0 && vy <= 0) //3
  17.                 otherAngle = (otherAngle+180)%360;
  18.             else if(otherAngle <= 0 && vy >= 0) //2
  19.                 otherAngle = (otherAngle+180)%360;
  20.             else if(otherAngle <= 0 && vy <= 0) //4
  21.                 otherAngle = (360+otherAngle)%360;
  22.            
  23.             double component = otherSpeed*cos(otherAngle-(myAngle+90)); //get the perpendicular component
  24.             double aimAngle = acos(myShotSpeed/sqrt((myShotSpeed*myShotSpeed)+(component*component))); //determine angle offset to make an intercept shot
  25.             if(component < 0) //use the sign of the component on the aim angle
  26.                 aimAngle = -aimAngle;
  27.             return aimAngle;
  28.         }
  29.         return 0;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement