Now the problem I am facing is how to scale the x and y increment of the rocket to the target so that it looks realistic.
How realistic is this?
I am not a rocket expert, but I would suggest that once launched simple rockets can be approximated by a fixed direction and speed. Then they just keep going in that direction until they hit something, run out of fuel, or gravity dumps them. When a rocket leaves, you can save its direction and speed and transfer the radio to the appropriate constant distance at each step (you can use trigonometric formulas to convert to x and y coordinates).
double delta_distance = speed * delta_time; double delta_x = Math.cos(angle) * delta_distance; double delta_y = Math.sin(angle) * delta_distance;
As stated in the comments, you can use the velocity vector instead of separately storing the angle and speed.
Minor note: constant speed is only an approximation for a few reasons. When the first rocket starts, it should accelerate until the thrust is equal to the resistance from air resistance. In addition, when the fuel burns, they can actually travel faster due to the fact that they have the same power, but less mass. But this level of detail is not needed for the tower defense game. Constant speed is a reasonable simplification.
I donβt think this algorithm will work well for you if your targets can move and change quickly because missiles can often miss their targets.
More advanced heat-seeking missiles will be able to fix the target and follow it. They should be able to change direction when their target moves, but I think they probably don't adjust their speed. They will also be limited by how quickly they can change direction due to physical limitations, so you can also simulate this. Otherwise, you may have missiles flying past the target, and then suddenly flipping over and immediately flying in the opposite direction without first slowing down or turning - and this is not very realistic.
Complex missiles may try to predict where their target is moving based on their current speed. They would calculate such a path so that the current trajectory of the target collides with the calculated trajectory of the rocket. This calculation should be updated if the target movement changes. Obviously, this is a little harder to implement, but remember that your players want to have fun with explosive monsters. They will not have much fun if all the missiles do not miss their targets. So a little extra work to ensure that your missiles are realistic and effective will make your game better.
source share