Predictive aiming while on the move

I am making a space game and want the player to target another ship and fire their cannons and have the cannons attempt to aim correctly for a shot. This currently works if the enemy is moving or both are still or low speeds as it only checks the velocity of the target. But if the player gets to moving fast it throws off the aim quite a bit and I’m not sure how to fix it. The second image below creates an aim vector for the cannons to rotate towards.

Hey there @Spacemarine658! So basically you’re trying to get the predicted location of where the target will be based on it’s current speed in a specific set of time (guessing the time in which it will take for the bullets to travel).

If your ships can only forward fire, the math should be relatively straight forward. This is in a 2D gamespace like your illustration or will it be fully 3D maneuverable?

If 2D gamespace and the guns only forward fire:

Player Forward Vector multiplied by how fast it’s moving in cm/s should give you a relatively decent tracking point that can be thrown off by player’s turns or speed fluctuations. Then you have to account for travel time, and that’s where the math gets a bit funky. If the distance is 3000cm away, then you need to account for 3 seconds between shot and player location. So you’d multiply the player’s front vector’s distance by 3, as we established it’s moving 1000cm/s, we know it will be exactly 3 seconds for it to go 3000cm.

I’d give more specific numbers but not entirely sure how your combat situation is set up so I just assumed a bunch.

1 Like

Hey I appreciate the help it’s 3d with moving turrets but I actually figured it out with some testing it’s surprisingly straight forward.

(the target Velocity * projectile travel time - the player Velocity * projectiles travel time) + the target location = look at vector point

So far in my testing this seems to work wonderfully even at extreme speeds

1 Like

You got it perfect! Now a game worked with has combat similarly, and with the AI we have one more variable to be able to fuzz the AI a little more when the player is moving fast as to make it more prone to missing if the player is doing quick maneuvering. This is not 100% necessary, but also helps eliminate the enemy “lasering” players effectively and makes skill expression more fun.

1 Like

Oooooo that’s actually a really good idea I was thinking about something like that for the player too (mostly to encourage the player to plan ambushes more carefully) high speed G maneuvers should be difficult to shoot from

1 Like

Design wise it may even be more rewarding to leave the player’s accuracy as close as possible to what they are trying for to encourage skill expression during high speed maneuvering. If they can whip around like a madman and still hit flashy shots, it’s often better to reward it. Games like Dishonored do this very well, at the most basic level of play, the game feels good with clear goals, but seeing someone play the game at the highest level is just insanely cool, due to the mechanics allowing you to be rewarded for perfect play.

A scaling noise value on relative speed to target for all shouldn’t be bad, but for players it may detract from their skillful play if they miss through no fault of their own. (obviously some games like roguelites prefer it this way so it’s case by case)

1 Like