Missile tracking algorithm

Source: Internet
Author: User

Many friends who have played flying shooters are impressed by the ability to track missiles, which are often invincible, but the enemy's missiles may be a nightmare for the player. In fact, the implementation of the missile tracking method is not complicated, only need some simple plane analytic geometry knowledge can be done.
The algorithm analysis assumes that the rotational angular velocity of the missile is Omega and the motion speed is v. Shows the initial state of the missile and the target in the axis.

At the initial moment, the target and the direction of the missile is Y, the position is (x1,y1), (x2,y2), the coordinates of the missile and the target, to get a line segment, the angle between the line and the y-axis is C; The angle of the missile with the-y direction is b,b, which is 0 The angle between the missile direction and the line segment is a,a that the missile still needs to be rotated. At this time

C=90-math.atan2 (y2-y1,x2-x1) *180/math.pi; b=0; A=c-b;

To conveniently calculate a positive value that converts C to 360 degrees:

C= (270+math.atan2 (y2-y1,x2-x1) *180/math.pi)%360;

After these values are obtained, the rotation angle and position of the missile at the next moment can be calculated. If a is less than the angular velocity Omega, the missile rotation angle A, just can point to the target, otherwise it will rotate Omega degree, so b=a<omega?a:omega; Copy code missile position becomes more

X2=x2+math.sin (b*math.pi/180) *v; Y2=y2+math.cos (b*math.pi/180) *v;

At the new moment, the target moves to a new position, while the missile rotates at a angle of B, as

The above calculation is then corrected to correct the position and rotation of the missile, so repeated until the missile hits the target or is destroyed due to a time limit.

Missile tracking algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.