Skip to content Skip to sidebar Skip to footer

Why Isn't My Homing Missile Algorithm Working?

I've taken code that's heavily inspired by this answer but my projectile is not homing in the way I expect. The initial projectile direction is often perpendicular to the target.

Solution 1:

According to me, if you have a vector (x,y) and you want to rotate it by angle 'theta' about the origin, the new vector (x1,y1) becomes:

x1 = x*cos(theta) - y*sin(theta)

y1 = y*cos(theta) + x*sin(theta)

(the above can be derived using polar coordinates)

EDIT: I'm not sure if I understand correctly, but if you know the speed and the absolute value of the final angle (say phi), then why can't you simply do:

Vx = speed*cos( phi )

Vy = speed*sin( phi )

EDIT 2: also, while taking cos-inverse, there can be multiple possiblities for the angleinradians. You may have to check the quadrant in which both vectors lie. Your maximum turning rate is 50 degrees in either direction. Hence, the cosine for that angle shall always be positive. (cosine is negative only for 90 to 270 degrees.

EDIT 3: I think to get information about +ve turn direction or -ve turn direction, cross product is a better idea.

EDIT 4: Vx / Vy should work if you carry out the following:

initialAngleInRadians = Math.atan(normalizedVelocity.y / normalizedVelocity.x)
finalAngleInRadians = initialAngleInRadians + angleInRadians
Vx = speed*cos(finalAngleInRadians)
Vy = speed*sin(finalAngleInRadians)

Post a Comment for "Why Isn't My Homing Missile Algorithm Working?"