in my code i gave a rigid body mass, so it falls while physics is being calculated. then soon after this (i mapped it to a keypress) i set it to static so it floats but is still solid. then after this i set it to static(false) and it still is static. any ideas on how to get this to become kinematic again?
There are three types of objects: “static”, “dynamic” and “kinematic”. Kinematic objects are not affected by any physical force - only by direct user input. This is why they are used e. g. for character controllers.
Making the object kinematic is probably the issue with your code.
i tried that originally, i think i fixed my problem though.
i had world.doPhysics(globalClock.getDt()) running constantly in a task. if i paused the task and switched the static to dynamic and then unpaused the task it now works. thanks for the nudge, i didn’t even think the task could be getting in the way.
also on same page, for contact test example there is:
result = world.contactTest(node1, node2)
which isn’t possible for 2 arguments, it seems. I figured out how to use it properly but I am just curious really.
here’s some example code where it shows that it is always colliding:
from panda3d.core import Vec3
from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletPlaneShape
from panda3d.bullet import BulletSphereShape
from panda3d.bullet import BulletRigidBodyNode
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletDebugNode
from panda3d.core import Point3
base.cam.setPos(-15, -55, 15)
debugNode = BulletDebugNode('Debug')
debugNP = render.attachNewNode(debugNode)
world = BulletWorld()
world.setGravity(Vec3(0, 0, -9.81))
shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
node = BulletRigidBodyNode('Ground')
np = render.attachNewNode(node)
np.setPos(0, 0, -2)
#model = loader.loadModel('models/box.egg')
shape2 = BulletBoxShape(Vec3(.5,.5,.5))
node2 = BulletRigidBodyNode('box')
np2 = render.attachNewNode(node2)
np2.setPos(0, 0, 55)
pause = False
if pause: pause=False
else: pause = True
dt = globalClock.getDt()
if not pause:
if node.checkCollisionWith(node2): #always true?
print "colliding at " + str(np2.getPos())
result = world.contactTest(node)
for contact in result.getContacts():
Well, because it should return true. I should admit that (1)the explanation on the manual page has been outright wrong, and (2) I probably should not have exposed this method anyway since it leads to confusion.
checkCollisionWith is used internally by Bullet to skip collision testing if two objects are linked by a joint/constraint. It has nothing to do with actual collisions of objects. The method you probably want is world.contactTestPair (see below).
The method to check for contacts between two bodies is “contactTestPair”. It has been wrong on the manual page. Page is fixed now.
When using the code given, after the node2 is at rest for a few seconds, its debug wireframe turns green. After that, it cannot be made white again. This does not appear to be correlated with its “static” or “dynamic” state.
I do notice that the ground plane is green, as well.