[resolved]little problem with the basic physics engine

I tried to use the basic physics engine with panda, but i didn’t succed:
here is my source code:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.actor import Actor

base.cTrav = CollisionTraverser('traverser')
pusher = PhysicsCollisionHandler()

Node = NodePath(PandaNode('physics'))
suzane = loader.loadModel('models/suzane')
suzane.setPos(0, 50, 10)

an  = ActorNode('suzane')
anp = Node.attachNewNode(an)
collider = suzane.find("**/suzane_collide")
base.cTrav.addCollider(collider, pusher)#here is the problem

gravityFN = ForceNode('gravity')
gravityFNP = render.attachNewNode(gravityFN)
gravity = LinearVectorForce(0, 0, -1)



suzane.egg is a model i made my self with blender(i added a collide object):

ModelRoot suzane.egg
    CollisionNode suzane_collide (1024 solids) T:m(scale 1.4566) (hidden)
    GeomNode suzane (1 geoms)

The problem is that the program is really slow and i get unexpected result.


Well, did you try simplifying your collision mesh and maybe octreefying it?

my collision mesh is not complicated at all. i think there is an error somewhere in the code!

this is the source code + the models so you can test your self!

You’re trying to let a 968 triangle model collide with a 2046 triangle terrain!
First of all, Panda doesn’t support mesh-to-mesh collisions. But even if it would, that means 1.980.528 collision tests are performed every frame!

Either reconstruct the model using collision solids (spheres, probably) and

Also, you forgot to add your model to the collider.

pusher.addCollider(collider, anp)

When I edit suzane.egg, and replace this line:

<Collide> { Polyset descend }

with this:

<Collide> { Sphere descend }

My FPS increases from 3 FPS to 900 FPS!
Of course, as you can see now, the sphere doesn’t fit tightly around the model - its probably better to approximate this model using three spheres.

Alternatively - you can use a physics engine that’s designed to handle this kind of collisions correctly, like ODE - but even ODE will be very unstable on this particular thing, so you’d even then need to approximate the shape with solids.

yes ,thanks for this precious information, it works now.

I Still don’t understand something, if i use Sphere descend, will panda compute automatically the center/radisu of the sphere from the polyset?

And also, the an is controlled by physics manager, the anp is controlled by the collision hadler, anp is apparented to the an. So if the anp moves, the physics engine won’t know about it. will it?

That is correct.

It will. NodePath is a mere wrapper around PandaNode/ActorNode. So you didn’t reparent anp to an (you can’t) but anp is more like a handle to modify ‘an’.
So if you move anp, you are actually moving ‘an’.

oh, it’s verry clear now