rigidBodies, gravity, collisions and kinematic bodies

areay

23-07-2010 10:27:02

Hi all,
I've been doing heaps of reading and have found the Bullet SDK Manual extremely useful http://bulletphysics.org/mediawiki-1.5. ... umentation

Anyway, I've got a question about rigidbodies

There are 3 different types of rigidbodies in bullet
1. Dynamic bodies (positive mass, every simulation frame updates its world transform)
2. Static bodies (zero mass, cannot move but just collide)
3. Kinematic bodies (zero mass, can be animated by user but all interactions are one way; dynamic bodies can be pushed away but there is no influence from dynamics objects)

So I've got a Ogre Terrain added into my scene with a HeightMapCollisionShape taken pretty much directly from the OgreBullet Terrain_Demo.cpp file

unsigned page_size = 513;

Ogre::Vector3 terrainScale(12000.0f / (page_size-1), 600, 12000.0f / (page_size-1));

Ogre::String terrainfileName = "terrain.png";

float *heights = new float [page_size*page_size];

Ogre::Image terrainHeightMap;
terrainHeightMap.load(terrainfileName, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

for(unsigned y = 0; y < page_size; ++y)
{
for(unsigned x = 0; x < page_size; ++x)
{
Ogre::ColourValue color = terrainHeightMap.getColourAt(x, y, 0);
heights[x + y * page_size] = color.r;
}
}

mTerrainShape = new HeightmapCollisionShape(page_size, page_size, terrainScale, heights, true);

RigidBody *defaultTerrainBody = new RigidBody("Terrain", physicsWorld);
const float terrainBodyRestitution = 0.6f;
const float terrainBodyFriction = 0.8f;

Ogre::Vector3 terrainShiftPos( (terrainScale.x * (page_size - 1) / 2), 0, (terrainScale.z * (page_size - 1) / 2));
//Ogre::Vector3 terrainShiftPos(0, 0, 0);

terrainShiftPos.y = terrainScale.y / 2 * terrainScale.y;

Ogre::SceneNode* pTerrainNode = sceneMgr->getRootSceneNode ()->createChildSceneNode();
defaultTerrainBody->setStaticShape (pTerrainNode, mTerrainShape, terrainBodyRestitution, terrainBodyFriction, terrainShiftPos);

mBodies.push_back(defaultTerrainBody);
mShapes.push_back(mTerrainShape);


I do OgreBullet tutorial 2 and I've got the boxes dropping onto the terrain and bouncing around happily on the terrain collision shape under the effects of OgreBullet world's gravity. All's well at this point.

Now I want to create a player object and have it collide with the ground, be under the effects of gravity and also be movable by keypresses etc and this is where I run into problems.

If I set my player as a kinematic body with code like
defaultBody->enableActiveState();
defaultBody->setKinematicObject(true);
defaultBody->disableDeactivation();


then I can use body->getBulletRigidBody()->setWorldTransform(transform) to move it around. However, I go straight through the ground and gravity ceases to affect me. How do you guys get all these things to work? Collision callbacks?

If I don't set my user as a kinematic body then I can apply impulses to my player after setting it to defaultBody->enableActiveState. What will I lose by totally ignoring the kinematic body state?

I've read that dynamic rigidbodies can pretty much be ignored as static and kinematic do everything I'll need to do.

My goal is to have heaps of ninjas and robots walking around on the terrain, being affected by gravity and reacting to collisions with falling and launched boxes etc. What approach should I take?

I realise there's heaps of questions here, I'd appreciate a bit of a steer. I'll build a small church in honor of anyone that helps me :D

Cheers
Al

Fish

23-07-2010 12:19:08

Can you try this with your kinematic character? viewtopic.php?p=65712#p65712

The Bullet Game Kit has an example of a fully functional kinematic character controller.

- Fish