I have a heat seeking missile in a space shooter game that follows a moving target. The missile follows the moving target well enough, but I want it to be constantly rotated in the direction of the target. My current code is as follows:
-(void)updateHeatSeekerAngleTo:(CGPoint)direction
{
CGFloat angle = atan2f(direction.y, direction.x);
_heatSeeker.zRotation = angle;
}
This method is then called in didSimulatePhysics (because this renders sooner than update:) using the following:
[self updateHeatSeekerAngleTo:_target.position];
As mentioned, the missile follows the moving target beautifully, however, it has a VERY delayed rotation effect, and often follows the moving target in a sideways position, then finally pointing towards the target as it draws nearer. I tested the code on a stationary missile sprite and the stationary missile constantly points to the target as the target moves, but it does not do this when the missile is in motion. How can I get the missile to point to the moving target constantly while in motion?