Panda Physic engine : simulating gravity.

Return to C++ coding using Panda3D

Panda Physic engine : simulating gravity.

Postby m.grumme » Mon Jan 31, 2011 12:54 pm

Hey there,

I am trying to enable simple physics behaviour using the internal physic engine, which should be enough for my needs.

I have a generated model, built vertex per vertex (using GeomVertexData...). I need this model to be affected by a gravity force.

The problem is, the section of the manual is quite unclear and uses python code, even in the c++ version.

I have tried to "translate" into c++ but that does not work. My code is as follow :

Code: Select all
PT(GeomNode) gn = c->generate();

   pm = new PhysicsManager();

   NodePath test = window->get_render().attach_new_node(gn);
   ActorNode an("an-physics");
   NodePath anp = test.attach_new_node(&an);

   ForceNode gravityFN("world-forces");
   NodePath gravityFNP = test.attach_new_node(&gravityFN);
   LinearVectorForce gravityForce(0,0,-9.81);



This simply does nothing. Using PhysicsManager.debug_output() gives me this :

Code: Select all
PhysicsManager li0 ai0
 _physicals 1
 _linear_forces (1 forces)
  _fvec 0 0 -9.81
  LinearForce(id 0030FA8C)
   _amplitude 1
   _mass_dependent 1
   _x_mask 1
   _y_mask 1
   _z_mask 1
   BaseForce (id 0030FA8C):
    _force_node render/gn*/world-forces
    _active 1
   _angular_forces 0

I'm running out of ideas here, if anyone got one...

Thanks in advance !
Posts: 3
Joined: Mon Jan 31, 2011 12:44 pm

Postby tah » Tue Feb 01, 2011 12:47 am


Did you create an AsyncTask ?

I know when I was doing particle system I had to add a task to update the PhysicsManager.


In my include file:

PhysicsManager mPhysicsManager;

static AsyncTask::DoneStatus updateEffectsTask(GenericAsyncTask* task, void* data);

PT(AsyncTaskManager) mTaskMgr;

PT(GenericAsyncTask) mUpdateEffectsTask;

In my cpp file:
LinearEulerIntegrator *lei = new LinearEulerIntegrator();

mUpdateEffectsTask = new GenericAsyncTask("mUpdateEffectsTask", (GenericAsyncTask::TaskFunc*)Effects::updateEffectsTask, this);

mTaskMgr = AsyncTaskManager::get_global_ptr();
then in your task (my class is called Effects)
AsyncTask::DoneStatus Effects::updateEffectsTask(GenericAsyncTask* task, void* data) {

Effects *effects = (Effects*)data;

float dt = ClockObject::get_global_clock()->get_dt();

return AsyncTask::DS_cont;


You might need to do something like this, but in your
case just do the:

Posts: 173
Joined: Fri Oct 29, 2010 3:25 pm
Location: Torrance, CA.

Postby m.grumme » Tue Feb 01, 2011 11:22 am


Thank you for your answer :)

I actually forgot to mention it but I do have an AsyncTask including the pm->do_physics(dt), yet it still doesn't work.

I must have messed up with something along the creation of the force, but in a lack of any example to refer to, I can't find it. Which is pretty frustrating, actually :/
Posts: 3
Joined: Mon Jan 31, 2011 12:44 pm

Postby tah » Tue Feb 01, 2011 5:01 pm

Hi again

looking at your code I see you attached actor node to the model node (test). In the manual they show attaching the model to the actor. Also they show attaching the gravityFN to the top render node, it looks like you attach it to the model node.


I think since your gravityFN is "hanging" under the model node as a child, so that force never gets applied to the model. That's why they put the forces at the same parent level as the models that need to have the force applied to them.

try doing:
NodePath gravityFNP = window->get_render().attach_new_node(&gravityFN);
Posts: 173
Joined: Fri Oct 29, 2010 3:25 pm
Location: Torrance, CA.

Postby m.grumme » Wed Feb 02, 2011 1:27 pm


Once again, thank you for looking into this :)

I tried your solution, that did not change anything.
Posts: 3
Joined: Mon Jan 31, 2011 12:44 pm

Postby siflux » Wed Dec 28, 2011 3:50 pm

I know this thread is most of a year old, but for posterity's sake I think I know what your problem is, having recently gone through a similar situation myself. I don't think you attached an integrator to your PhysicsManager. To copy a few lines out of of tah's big reply:

LinearEulerIntegrator *lei = new LinearEulerIntegrator();

Physics simply does not work in Panda3d unless your physics manager has an integrator attached to it AND do_physics is called every frame.
Posts: 3
Joined: Tue Dec 20, 2011 5:14 pm

Return to C++ coding using Panda3D

Who is online

Users browsing this forum: No registered users and 2 guests