Using Thinking Particles to create a ballistic analysis in a procedural way.

Whats going on in this video:

In most of the effects in movies when someone shoots a ball/laser/whatever the bullet is not affected by gravity, so to create a procedural system you simply need to use a alignment node to point directly the object you want to shoot. But what happen if the bullet is affected by gravity? here things start to be a little more complex, you need to give a specific angle to your bullet so with the initial velocity and the gravity impact on a very specific area. If you need to create a shoot like this you can do it by trying an error (you change your velocity/shooting angle until the bullet goes on the place you want, or you make some matematics calculating parabolic trajectories. But what if instead of shooting 1 object your scene has 100 canons shooting to a total of 1000 objects? you will take forever. For this I create a system that do it for you.

The original system detects your object to impact, obtaining horizontal and vertical distance. You give a specific initial velocity for the bullet and the gravity for all the system. Internally TP calculates the necesary rotation angle on the cannon so the bullet impacts on the selected object, after there is not predefined path, simply there is velocity on the ball and the general gravity.

As you can see there is always two angles that will make the ball impact on the target with the same velocity/gravity (is a second degree equation), you can switch between them on TP menu.

I can have diferent information like maximum distance the bullet can travel with the predefined initial velocity and general gravity (always at 45 degrees), the maximum height, If the ball will impact or not to object, the minimum velocity needed so the ball can reach his objective, the time of flying before the impact, and so on…

In the second example, with the basket ball is a little diferent: I give a fix angle and the system detects the necesary initial velocity to hit the target.

Basically I detect an object on scene and with a distance condition I save the distance information from cannon, after I create some equations using an expression helper in TP. A motion from a cannon can be decompose with his horizontal movement (constant) and his vertical movement (constantly accelerated by gravity action), from this equations we can create some new ones like:

Equation that define the parabolic movement:

Horizontal distance that the bullet can travel (Horizontal distance is the maximum when the angle is 45 º):

Vertical distance: Will be maximum when the angle is 90º.

Angle needed if we have a gravity and a initial velocity:

Thanks to Enric Lleonart for solving the last equation

Taking it further:

System is working well right now, but interesting things is all what you can do from here:

-A system with multiple targets: The canon will select procedurally one by one the targets to shoot, adjusting his angle for every one.

-A system with multiple targets and multiple canons: Every cannon selects a diferent target.

-Improve equations: Add to the equations air friction, wind, air turbulence, earth spherificity (for long distances), will make not so much visual impact, but… technically nice!

-Detect target velocity: The cannon can know what is the direction and velocity of the target and calibrate itself to shot on the good position, this will need to iterate diferent times the equations.

-Flexible velocity: Right now I have a fix initial velocity, but can be possible to define a range of possible velocities, so if thebullet can´t reach the target because velocity/gravity, can increase gradually his velocity using a maximum range.

-Imperfections: Right now cannons always hit his target objective, we can add some random values so not always cannons hit his objectives.

-Collisions: We can detect if any other object is inside the trajectory from cannon/target and make a secondary action if this is the case.