Draw a 3D Curve for a cannon's trajectory

Godot Version

4.4

Question

In a game like Angry Bird, the game shows the predicted trajectory of the bird when you are about to launch it.

Now, imagine a 3D game that you could control a cannon to shoot a cannonball, but instead of aiming like Angry Bird, I am looking for something different: imagine an RTS game that you place a cannon at a location and then you order it to shoot at a destination. Now, suppose the cannonball has a certain mass, the cannon will have to adjust its angle and apply a certain force to the cannonball so the cannonball will land at the correct position.

I would like to draw this predicted curve line of the cannonball’s trajectory. What would be the optimal way to do this?

Note: in fact, the more I think about this, I think this should be 2 questions. 1 is how to calculate in physics and work backward to get the angle and the force. 2 is how to draw the curve line with respect to the angle and the force.

Help > Programming

You probably want to pick up a reference book; I’d suggest Physics for Game Developers, 2nd Edition, but there are probably other good books out there.

The actual problem is relatively easy to solve; ballistics equations aren’t difficult math. It’s basically a solving a quadratic; you’ll get either two answers (the high angle and low angle versions), one answer (where the two answers converge at the edge of maximum range) or no answers (if it can’t shoot that far).

As for drawing, it depends on how you want it to look. You could use ImmediateMesh to construct and draw a line, you could give similar ballistics to a particle system, or breadcrumb sprites along the path…

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.