Tracking missiles
function(targetposition) {//How to move objects toward the target var Speed=5;varTargetPoint= Targetposition;varThispoint= CC.P ( This.x, This.y);//Find the difference between two points, in fact, two points of the coordinate subtraction varDelta= Cc.psub (TargetPoint,Thispoint);//Find the distance between the current object and the target two points varDistance= Cc.pdistance (Thispoint,TargetPoint);//Calculate the point xy coordinates after walking varX2=Thispoint.x+ Speed*Delta.x/Distance;vary2=Thispoint.y+ Speed*Delta.y/Distance;if( ->=Distance){return True; }//Change the position of the current object varnewposition= CC.P (X2,y2); This. SetPosition (newposition);//rotate the corresponding angle varX1=Thispoint.x;varY1=Thispoint.y;vardeltarotation= --Math.atan2(y2-Y1,X2-X1)* the/Math.PI; This. Setrotation (deltarotation);return False;}effect See game address http://www.seraph-fd.cn/games/1/index.html
COCOS2D-JS Missile tracking algorithm (while chasing the target moving one side rotation angle)