+1 vote

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?

asked Jun 9, 2019 in Engine by INeeedHealing (25 points)

1 Answer

+1 vote

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"

answered Jun 10, 2019 by sparkart (327 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.