Algorithm
First look at the effect of it:
The code is as follows:
/*
Ask you about a potential function to trace and intercept the algorithm
Has the research to be able to enlighten!
Powered by Sunday
Email:happyclub@163.com
*/
var stepangle:number = 3;
Maximum angle increment
var tempnum:number = 0;
var radius:number = 100;
Missile Flying radius
var m_speed:number = 3;
Missile speed (extraordinary amount)
var p_speed:number = 5;
Aircraft speed
Findtohit (missile, target);
function Findtohit (missile, target) {
Missile.onenterframe = function () {
_root. Angtext = Stepangle;
if (Missile.hittest (Target.hit)) {
Target.play ();
Missile._visible = false;
Delete Missile.onenterframe;
}
---------------hit the target.
tempnum++;
if (Tempnum = = 15) {
if (Stepangle = = 2) {
if (Math.Abs (target._x-missile._x) >radius*2 | | Math.Abs (target._y-missile._y) >radius*2) {
Stepangle = 3;
}
else if (Math.Abs (target._x-missile._x) <30 | | Math.Abs (target._y-missile._y) <30)) {
Stepangle = 2;
}
Tempnum = 0;
}
---------------------Change the angle increment-------------------------
P = new Object ();
p.x = missile.way._x;
P.Y = missile.way._y;
Missile.localtoglobal (P);
DX = p.x-missile._x;
dy = p.y-missile._y;
dx1 = target._x-p.x;
Dy1 = TARGET._Y-P.Y;
----------------------Get Vector--------------------------
Angle = Math.atan2 (dy1, dx1) *180/math.pi;
-----------------------Get an angle------------------------
Angle = angle<=0? Math.Abs (360+angle): angle;
M_angle = missile._rotation<0? 360+missile._rotation:missile._rotation;
if (Math.Abs (m_angle-angle) >stepangle) {
if (angle-m_angle>180) {
M_angle + =-stepangle;
} else {
M_angle + = Angle<m_angle && (m_angle-angle<180)? -stepangle: +stepangle;
}
Missile._rotation = M_angle;
}
---------------------Change the missile angle-----------------------
Missile._x + = DX*M_SPEED/10;
Missile._y + = DY*M_SPEED/10;
-----------------------Missile Movement---------------------
};
}
-----------------------------Tracking---------------------
Listen = new Object ();
Listen.onkeydown = function () {
Onenterframe = function () {
if (Key.isdown (key.right)) {
Target._x + = P_speed;
else if (Key.isdown (Key.left)) {
Target._x-= P_speed;
else if (Key.isdown (key.up)) {
Target._y-= P_speed;
else if (Key.isdown (Key.down)) {
Target._y + = P_speed;
}
};
};
Key.addlistener (listen);
----------------------------Keyboard Control--------------------------
Look at the source file: The game of missile tracking algorithm. rar