I’m not great at doing certain math. Could someone give me an idea how to handle doing heat seeking missiles.
So this is my game. Player is ALWAYS at 0,0. Everything is on Z=5. It is some what 3d, even though it is top down and you can not see it.
So everything on the screen has an adjustment to their position by doing the following code change (if you have a better solution, please let me know). Every object has a heading and the rotation is set based on that.
I what I need to do it based on the enemy’s heading, set the rotation of the Heat Seeking missile and then start to calculate how to make changes based on a (TIME rate) of making heading corrections and then allowing the player velocity to adjust its position on the screen.
I want to set the missile to only correct to a new heading once per period, and then keep moving that direction until next time elapse and then based on the players heading adjust new heading until the missile moves to the player.
I have a TOTAL elipse time to live for the missile, so player and each shoot it or out run it until it explodes.
This kind of geomerty is beyond me. Any help I would love it.
So it’s trying to lead the player? Like head to where they will be instead of where they are? (That’s the only reason I can think that player velocity would be necessary.)
Either way, this sounds like a classic steering problem. (If you wanted to do further research then that’s where to start.)
At least it sounds like it… you essentially want the missile to turn towards the player at some turning rate, right?
“playerHeading” is confusing me a bit, though. Is that the “way the player is heading” or the “direction of the player from the missile”?
Also, do these objects also have proper rotation to face where they are going and stuff? Or are they ‘directionless’ models? (Trying to decide if any code I provide would need to do the transforms or if the quaternions are already there to do the math for us.)
So play never moves, everything moves, to make it appear the player is moving. So the player has a velocity (movement speed), and then each item on the screen location is adjust based on the players heading and speed. So if the player is moving degree 0 North.
Every enemy and bullets have a direction and movement is based on their directions. So the missile will need to have its direction rotated to continue moving.
playerheading is the rotation (facing) of the player. All objects have a directions in the game.
I cannot grasp the full issue here. However I think you might be overcomplicating it at some point.
There is a point that may help you:
If you can interpolate the target position between n number of enemies for example.
And, use the time to calculate a periodic interpolation factor (e.g., use modular arithmetics or sine waves logic); then you might be able to change the missile heading completely from Enemy 1 to Enemy 2 based on a time factor.
What I will do to approach this problem? Is first write the enemy follower code. Then, do some tweaks to make the object following algorithm to change its heading based on some input. This by the way is a classic State-Machine case, too.
Maybe something like this:
// Calculate factor of lerp
float lerp = virtual_time % number_of_enemies;
// interpolate the target position
vector3f target = interpolate(enemies, lerp);
missle.adjustHeading(target);
You may try to simplify the problem logic, by envisioning 2 enemies only.