The missile knows where it is at all times. It knows this because it knows where it isn't...
A test/demo of a new system for my game project.

While working on ShipBasher I found that ships had great difficulty keeping their targets in range because their following behavior naively accelerated them toward the targets without accounting for the targets' movements. The fundamental problem here is the same as with a guided missile, so I set up a manually controlled target ship and a missile to prototype and test an improved homing behavior.

The missile uses its position and velocity relative to the target ship, from which it extracts its radial velocity - the component of its motion that is directly toward or away from the target - via vector projection, resulting in a correction vector. This is combined with thrust directly toward the target based on a "homing factor" determined by how large a correction is needed and how close the missile is to its target. The result is that the missile works to ensure its motion is as close to directly toward the target as possible and uses leftover acceleration to boost its speed while far away.

In theory this same logic can be used for ships, simply halting the approach when within range of a target.

Click and drag to rotate the camera around the target ship.
Use W/A/S/D to accelerate the ship relative to the screen.
Combine W/A/S/D and rotation to manage the ship's movement in 3D space. Try to dodge the missile and avoid being hit for as long as you can for a bit of challenge.

Each time the missile hits it will "launch" itself away from the ship and then resume its pursuit.

Note how the missile inevitably hits if the ship is left uncontrolled or maintains a constant acceleration. Trails are displayed to highlight the missile's flight path in pursuit and the complicated path that results from repeatedly dodging it.

I'll probably make a blog post explaining this in more detail later.

All artwork and code created by me with the exception of the background speech copypasta. No AI was used to create artwork or code for this project. I do not consent to this project being used to train AI data sets.

Comments

Log in with itch.io to leave a comment.

"Somebody shut the WSO up or I'll deviate his septum!"

Updated 29 June 2023 to fix the broken post processing.