JohnBoyManbullet
30-06-2011 03:58:08
Hello. I have created a character like this.
I am triying to get my character walking around. Im using impulses to do this. I tried sing the kinematic cahrater contorller but with no success. So im trying to make my own. I need my entity to always stay at the height of the terrain. I can get my character to walk up the hill, but on the way down he just floats. This if i try to increase the entitys mass then i have to increase the needed imulses and it isnt the right result. I see in the character control demo the character can just walk anywhere and not bounce up into the air. Is there a simple way of achiving this. Ill post the code when i get it working . Any tips please and thanks.
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(1500.),btScalar(1.),btScalar(1500.)));
collisionShapes.push_back(mGroundShape);
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,-2,0));
{
btScalar mass(7.);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass = 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,mGroundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
//add the body to the dynamics world
dynamicsWorld->addRigidBody(body);
}
{
btScalar characterHeight=30.75;
btScalar characterWidth =30.75;
btConvexShape* capsule = new btCapsuleShape(characterWidth,characterHeight);
/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
btScalar mass(10000);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,-1.0);
if (isDynamic)
capsule->calculateLocalInertia(mass,localInertia);
startTransform.setOrigin(btVector3(140,250,10));
// *** give it a slight twist so it bouncees more interesting
startTransform.setRotation(btQuaternion(btVector3(1.0, 1.0, 0.0), 0.6));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
//btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
MyMotionState* motionState = new MyMotionState(startTransform, boxNode);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,motionState,capsule,localInertia);
body = new btRigidBody(rbInfo);
body->setAngularFactor( .0f );
body->setFriction(0.8f);
body->setAngularVelocity( btVector3( 0.0f, 0.0f, 0.0f ) );
dynamicsWorld->addRigidBody(body);
}
I am triying to get my character walking around. Im using impulses to do this. I tried sing the kinematic cahrater contorller but with no success. So im trying to make my own. I need my entity to always stay at the height of the terrain. I can get my character to walk up the hill, but on the way down he just floats. This if i try to increase the entitys mass then i have to increase the needed imulses and it isnt the right result. I see in the character control demo the character can just walk anywhere and not bounce up into the air. Is there a simple way of achiving this. Ill post the code when i get it working . Any tips please and thanks.