# Heat-seeking missile code.

 0 Hey! So, I'm implementing heat-seeking missiles in a platformer game. Basically, I'm attempting to code a kind of inertial movement where the missile goes after an object (in this case, a helicopter) in the most efficient way possible. But that route will be limited by its turning radius--it won't be able to turn fast enough if the helicopter "dodges" it by moving out of the way.In any case, my strategy is to constantly adjust the angle towards the helicopter, and then just push the copter in the direction of a vector I'm constantly changing based on that rotation. I'm having trouble with the second part of that process. It seems to be doing something right, at times--because the missile generally will go in the direction of the helicopter. Any idea what I'm doing wrong, here? Let's assume, for the purposes of sanity, that the missile always starts at angle 0. `````` void Update () { AdjustAngle(); transform.position += directionVector; // updated in adjustangle } public void AdjustAngle() { //aim for the target. move an increment toward the target if it's not aiming at it within a certain range. //move in the direction the missile is facing. angleOfChopper = GetAtan2Deg(); maxMoveDistance = missileSpeed * Time.deltaTime; amountToRotate = missileTurnRadius * Time.deltaTime; if(angleOfChopper < transform.eulerAngles.z) { transform.Rotate(0,0, -amountToRotate); directionVector = new Vector3( -1* maxMoveDistance * Mathf.Cos(amountToRotate), maxMoveDistance * Mathf.Sin(amountToRotate) , 0); } if(angleOfChopper >= transform.eulerAngles.z) { transform.Rotate(0,0, amountToRotate); directionVector = new Vector3( maxMoveDistance * Mathf.Cos(amountToRotate), -3 * maxMoveDistance * Mathf.Sin(amountToRotate) , 0); } } public float GetAtan2Deg() { float yDist = gameObject.transform.position.y - chopper.transform.position.y; float xDist = gameObject.transform.position.x - chopper.transform.position.x; return Mathf.Rad2Deg * Mathf.Atan2(yDist, xDist); } } `````` more ▼ asked Apr 20 '12 at 05:29 AM Catlard 527 ● 47 ● 57 ● 62 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x289
x286
x102
x41
x4

asked: Apr 20 '12 at 05:29 AM

Seen: 746 times

Last Updated: Apr 21 '12 at 11:20 AM