Noob with physics engine question.

First let me start by saying Hi. I’ve been reading these forums for a while now and I’m just about ready to make a start on a project using Panda.

I have a couple of questions about the capabilities of the ‘basic’ physics engine that I’d like to try and get answers for before I write a load of python code that doesnt work.
Basically I want to simulate a bat hitting a ball that is travelling towards it at speed. If I use the built in physics engine with PhysicsCollisionHandlers and I apply a force to the bat to simulate the swing, will the physics engine automatically recalculate the velocity/direction of the ball when it collides with the bat, or will I have to catch an event on the collision and calculate the force applied to the ball in the event handler?
Also, If i move an ActorNode by calling getPhysicsObject().setPosition() over a number of frames (instead of adding linear force) will the Physics engine update the objects velocity accordingly? or do I HAVE to apply a force to the ActorNode?

Hope someone can give me some pointers


The physics system does not transmit velocity like that–so you’ll have to compute the velocity in both cases.


As an addendum, even a simple seeming interaction like a bat hitting a ball can be pretty tricky. You might want to look in the Open Dynamics Engine, or ODE, an open source physics simulator.

With ODE you basically run a simulation of basic shapes like spheres and cylinders, applying forces instead of moving objects explicitly (though you can also do this if you need to), and then you read the position and rotation of the simulation objects and use this to position your Panda graphics objects directly.

ODE has Python bindings and should happily coexist with Panda3D.

Thanks for the pointers guys. You’ve saved me a lot of ‘banging head against the wall’ time :slight_smile:
I have looked at ODE (and even considered knocking up some python bindings for Newton or Tokamak) but I thought I’d better find out whether the built in physics stuff could do what I wanted first.
I’m also looking at doing a table tennis sim which is going to require some physics so maybe getting my head around ODE is a good idea.


if you’r doing sport games physics might !can! be a !very! ugly way to achieve something.
sometimes its a lot easyer to code the stuff yourself like it’s usualy done.
basic math (vector math) , a good schoolbook and some fiddling and things behave more “real” than when using physic engines. the only games i would recomend a physic engine for would be billiard, bowling or motorsports.

all others usualy are better of with some simple functions which descibe the movement of a “something”. using manual calculation can prevent some very nasty errors and usualy requires less cpu-power.

if you have a table tennis sim you really should concider using home-made algorithms. especially since the ball’s flight is affected by its rotation ( when its in the air) and i havent really saw a physik engine concidering this.

btw. there are python bindings for ODE ( ithink it only works with the cvs version but it’s quite fine)

I think if its left up to me, I might end up with a really wierd acting ping pong ball :laughing:

Looks like I’m going to be doing some experimentation…