"Parabolic" interval?

Dear gentlemen,
I try to implement a 17th century cannon. The cannon-ball is supposed to be visible and slow enough, and it has to move along parabolic curve. Is there any interval to implement such parabolic movement? Or any other ideas?

use the LerpFunc and physics equations
x = x0+vx0t
y = y0+vy0
z = z0+vz0t+.5ttaz

0 is initial; v is velocity; a is acceleration; x,y,z is position (vx is velocity in x direction and so on)

Thank you, mindstormss!
But I am not sure if it helps. I forgot to mention that initially I know only start and end points of parabola. Velocity and acceleration are unknown.

There’s always an acceleration, in your case the gravitational acceleration - if, for example, one panda unit equals one meter in your scene, the acceleration is around 9.81 m/s². The velocity is then 9.81 * globalClock.getDt().
Since the velocity differs per frame (at the start, its usually 0) I kinda doubt mindstormss’ equation.

Oh, thank you! I totally missed this point. Now I understand :slight_smile:

All of these equations that I have given are derived from the physics kinematic equations. They are accurate and will give a parabola. They do assume that at time 0 a force is applied to the object and no force other than gravity is applied past that. They are deterministic, while the other approach basically becomes an euler approximation of these equations (almost same result; less accurate but more flexible)

Ode and other physics engines use these equations with more advanced integration and such; it may be a good idea to simply use that. They hide all of this behind the scenes.

If you know the start/end point, then you have to know the total time to travel as well. Acceleration in this case is simply gravity, a constant. (might be -9.8 m/s/s, but depends upon scale of your game) It is negative in most all cases (including yours) Adjust it to look correct.

x = xi + (xf-xi)/totalTimet
y = yi + (yf-yi)/totalTime

vzi = (zf-zi-.5totalTimetotalTimea)/totalTime
z = vzi
t + .5tt*az

i is initial position; f is final position. totalTime is the time it takes to get from (xi,yi,zi) to (xf,yf,zf). vzi is constant across the entire time span; simply needs to be calculated at the beginning and saved for use in the function.

And don’t overlook Panda’s built-in ProjectileInterval class, which does all of these calculations automatically.

Of course, it is helpful to understand the math in the first place, so that you understand what it is doing.


Amazing Panda! It has everything. Thank you, David.

My cannonballs are going to move rather fast, and I have to use collision detection mode for rapidly-moving objects.

To do so, I have to setRespectPrevTransform(True) and also to change the position via setFluidPos(). While LeprInterval allows me to specify this way of moving a nodepath, the ProjectileInterval doesn’t. Does it mean that “fluent” collision detection won’t work with it without some workaround?

That’s actually the default mechanism employed by the ProjectileInterval.

Note, though, that the fluid motion will only be drawn in a straight line from the cannonball’s previous position each frame. As long as your cannonballs are not moving so fast (and you never have a long enough frame chug) that your linear approximation of a parabola is good enough, this will be fine. But if you have a long frame chug where the cannonball is at the start of its arc in one frame and then near the end of its arc in the next frame, it will skip over most of the arc and appear to move in a shortcut to its destination.

Consider using the collNode parameter to the ProjectileInterval constructor. This creates a special CollisionParabola object which will always represent the part of the arc that the cannonball is passing through each frame. You can add this node to your CollisionTraverser for very accurate cannonball collisions.

You are lucky that we happen to have just solved several of these sorts of problems for Disney’s Pirates of the Caribbean. :slight_smile:


Thank you very much, David! Now I start to understand that collNode is probably the best solution in my case. Your help is invaluable, David, thank you again! Every time I stumble upon any difficulty, I discover that Panda3D has almost all solutions built-in. What a wonderful engine!