Predict the path of a projectile

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By INeeedHealing

I have a projectile with known position, velocity and gravity. How do I predict where it will be in the future and where it will hit a wall?

:bust_in_silhouette: Reply From: sparkart

You can create a “ghost projectile” which basically calculates what your projectile will do and just let the physics engine do the calculations for you. You also get the added benefit of graphical feedback of the calculation.

Alternatively you can use the projectile motion formula. Just do a google search on that, there is a lot of information about it.

Since you also need to calculate where it would hit a wall, the first method is probably the easiest, since you’re gonna have to trace the projectile’s path and test for collision each step.

To make the calculation instantaneous, you can also scale the velocity and gravity of the “ghost projectile”

I think this is quite a nice idea to begin with, especially for things like implementing AI to shoot projectiles.

For using formulas to solve trajectories, this article is pretty elaborate upon the first glance.

Xrayez | 2019-06-11 06:04

This helped a lot. For anyone from the future who found this and still couldnt figure out how to properly scale your velocity to make the ghost projectile instant:

You can put your physics code in another function and run a for loop.

func _physics_process(delta):
for i in 2: # speed multiplier
	_physics(delta)

func _physics(delta):
    # movement code here

sollysmyth | 2022-06-12 18:22