Attaching rigidbody to a bone

swifft

14-12-2010 20:44:38

Hello. I am trying to attach a rigidbody to a bone on a skeleton. To do this I have created a SceneNode* and passed that to the rigid body. I then update the SceneNode*'s position every frame based upon a bone's position.

m_arrBodies[i]->m_pRigidBodyNode->setPosition(m_arrBodies[i]->m_pTagPoint->_getDerivedPosition()

When I run the program the debug drawing shows my collision objects at the correct position, but the collision does not always work. It works on some of the rigid bodies but not on others, and sometimes I get collision with the wrong rigidbody. Keep in mind that if I do not run the animation (i.e. if the bone's position never changes) all collisions work fine. Can anyone help?

Fish

15-12-2010 12:28:33

Usually, Bullet handles the updating of SceneNode position and orientation. With Bullet, the RigidBody controls the SceneNode position and orientation, not the other way around. Updating the SceneNode directly usually has bad results. I think you should update the worldTransform of the bullet RigidBody using

// Get the current transform
btTransform xForm = mOgreBulletRigidBody->getBulletRigidBody()->getWorldTransform();

// Manipulate it with the skeleton tag data.
// Set the new position in the transform.
btVector3 newWorldPosition(tagPosition.x, tagPosition.y, tagPosition.z);
xForm.setOrigin(newWorldPosition);

// Set the orientation.
// Insert code here, don't remember the bullet method names off the top of my head.

// Finally move the RigidBody and the SceneNode that the RigidBody controls
mOgreBulletRigidBody->getBulletRigidBody()->setWorldTransform(xForm);


- Fish

swifft

15-12-2010 19:16:53

Thank you. This has fixed my issue. I might still be doing something wrong because if I only update the RigidBody's worldTransform the collisions work but the debug drawer doesn't update the position of the rendering shapes, but when I update both the RigidBody and the SceneNode I get correct collisions and correct debug drawing. It seems the RigidBody is not updating the SceneNode like it should be and the debug drawer uses the Node's position to render shapes. Either way its working now but I am interested to know if I am not using the system properly.

Thanks again for your help.

BenM

16-12-2010 04:56:50

Ah, interesting, I'll have to try this. I've had basically the same problem, and I'd noticed myself that if I turned off physics, all my rigidbodies would suddenly spring into the correct position, but as soon as I turned it back on, they'd go flying off.

Fish

19-12-2010 04:56:27

The visual representation of the rigidbodies is drawn by OgreBullet. It's possible there is a bug. If you track it down, please submit a patch to the tracker.

- Fish