Physics slows down?


I started physics and I have some questions.

In the beginning I ran my game without physics and it was nice, but when I applied physics, frames per seconds decreased. It was with medium size map. When I load large map, frame rate went to zero. Then I thought I was using wrong classes. What is the best to use physics. I clone my model, apply it in PhysicsGhostNodes, then add in physics spase and attach to node that attached to root node.

That walls are PhysicsGhostNodes and I’m using PhysicsGroupCollisionListener (group 1 for tank, group 2 for walls , group 3 for bullets).

May be I should use other things?

The other thing is models disappear at the edge of window, It didn’t before.

Thank you for reply.

Try CollisionShapeFactory.createDynamicMeshShape(). If you wanna apply physics to your scene as a whole ( except the tanks and bullets )

try CollisionShapeFactory.createCompoundCollisionShape() to it. And try CollisionShapeFactory.createDynamicMeshShape() to the tanks and bullets. If the bullets are spheres then try SphereCollisionShape to it. If you wanna test if your meshes’s collision shapes are at right location,

then attach DebugShape to them.

No, dont use createDynamicMeshShape! It will result in too high CPU usage. You should use basic collision shapes and combine them in CompoundCollisionShapes for more complex shapes that are supposed to move. Mesh shapes should only be used for static physics objects.

Look at this thread for some hints about possible problems and/or improvements.



First sorry for my english ( because I’m br :slight_smile: )

I came to the conclusion to use DynamicMeshShapes because I made a class that ran all the nodes of a scene and changed the PhysicsNodes’ CollisionShapes. I made it because you just create “CompoundCollisionShape” to yours PhysicsNode at SceneComposerWindow, and that kind of CollisionShape has no mass. So my class altered these CompoundCollisionShapes to DynamicMeshShapes in only one method. Has somehow to change all PhysicsNodes’ CollisionShapes in my class for a kind of CollisionShape efficacy (in just one method, by passing a PhysicsNode as parameter) ???

Yes, the collision shape generation in the SceneComposer is meant for scenes, so non-moving objects. There is no way to one-click create a CompoundCollisionShape of basic shapes (Box, Cylinder etc.) yet in jMP if thats what you are asking for. Dynamic Mesh shapes are simply too costly. You will have to build your Collision Shape “by hand” as I described in the thread.

And if I to use this method to all my movable meshes:


CollisionShapeFactory.createCompoundShape(rootNode, new CompoundCollisionShape(), false), 1


Would be a good way out???

That method tries to create a collision shape made out of boxes that surround the single geometry objects in your model. You can try it but the manual method will be better.

1 Like

OK, now can i understand. For example, if I wanna create a CompoundCollisionShape to my character I’ll have to combine it with :

  • 1 SphereCollisionShape to its head;
  • 5 BoxCollisionShape to: its body, arms, and legs.

    I’m more or less right?

I was able to fix disappearing of the models and increase frame rate from ~1 to ~20, but still I It is too slow.

So I have another question. Will it be better to attach all my wall model to one node and in singleUpdate() check for


res = tank.collideWith(walls, result);



res = tank.collideWith(walls, result);

This is not jbullet,

What you are doing is a manuall intersection check, wich is probably a few dozen times less efficient in a static enviroment. I suggest rereading the jbullet examples (or take a look at the test.jbullet.* package)