How to calculate projectile prediction for shooting a moving enemy (turret system)

Hello,

I’m working on a turret system in GDevelop 5 and I’m having an issue with shooting moving enemies.

The turret currently aims at the enemy’s current position, so when the enemy is moving, the bullets often miss because the enemy changes position before the projectile arrives.

What I want to achieve is projectile prediction (lead targeting), so the turret shoots at the position where the enemy will be. The enemy can move in any direction (including diagonally and changing direction), and the projectile has a fixed speed.

What is the recommended way to calculate the future position of the enemy and aim the turret correctly using GDevelop events?

Thanks! :slight_smile:

*a representative image of what I want

What you’re trying to do is predict the intersecting point of a moving enemy and a bullet fired from player. This StackOverflow thread answer by boofra appears to be a good solution. It is quite mathematical though, but this can be converted into events or javascript.