Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double PredictMovementAim(Actor other, double myShotSpeed)
- {
- //Determine if we even need to adjust our aim
- if(other.vel.x != 0.0 && other.vel.y != 0.0)
- {
- double myAngle = self.angle % 360.0;
- double otherSpeed = other.vel.Length();
- double vx, vy;
- vx = other.vel.x;
- vy = other.vel.y;
- //get a (-90, 90) angle
- double otherAngle = atan(vy/vx);
- //correct it to (0, 360) using quadrants
- if(otherAngle >= 0 && vy <= 0) //3
- otherAngle = (otherAngle+180)%360;
- else if(otherAngle <= 0 && vy >= 0) //2
- otherAngle = (otherAngle+180)%360;
- else if(otherAngle <= 0 && vy <= 0) //4
- otherAngle = (360+otherAngle)%360;
- double component = otherSpeed*cos(otherAngle-(myAngle+90)); //get the perpendicular component
- double aimAngle = acos(myShotSpeed/sqrt((myShotSpeed*myShotSpeed)+(component*component))); //determine angle offset to make an intercept shot
- if(component < 0) //use the sign of the component on the aim angle
- aimAngle = -aimAngle;
- return aimAngle;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement