COCOS2D-JS Missile tracking algorithm (while chasing the target moving one side rotation angle)

Source: Internet
Author: User

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)

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.