Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double PredictMovementAim(Actor other, double myShotSpeed)
- {
- double myAngle = self.angle % 360.0;
- double otherSpeed = other.vel.Length();
- double otherAngle;
- //get a (-90, 90) angle and correct it to (0, 360)
- if(other.vel.x != 0.0 && other.vel.y != 0.0)
- {
- otherAngle = atan(other.vel.y/other.vel.x);
- if(otherAngle >= 0)
- {
- if(other.vel.y <= 0)
- {
- otherAngle = (otherAngle+180)%360;
- }
- }
- else
- {
- if(other.vel.y >= 0)
- {
- otherAngle = (otherAngle+180)%360;
- }
- else
- {
- otherAngle = (360+otherAngle)%360;
- }
- }
- }
- else
- {
- otherAngle = 0; //it really doesn't matter what this is, so long as it's defined. The magnitude is zero
- }
- double component = otherSpeed*cos(otherAngle-(myAngle+90)); //get the perpendicular component
- double aimAngle = acos(myShotSpeed/sqrt((myShotSpeed*myShotSpeed)+(component*component)));
- if(component < 0) //use the sign of the component on the aim angle
- aimAngle = -aimAngle;
- return aimAngle;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement