Chacter Control

JohnBoyManbullet

30-06-2011 03:58:08

Hello. I have created a character like this.
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.

captaincrunch80

17-07-2011 08:56:48

John forget that approach you have to control your character with raycasts and position setting and can not leave this to the physics engine.
Try walking up a stair with an immobile box body...


Check out this article
http://bulletphysics.org/mediawiki-1.5. ... tionStates


Kinematic Body is what you want! The body does not move you (no gravity etc) you move the body each frame according to your camera. And the body kicks the other Rigidbodys around, but you have full control. Make sure you move the RigidBody via it's motion state and nothing else.


Read carefully http://bulletphysics.com/ftp/pub/test/p ... Manual.pdf PAGE 24 and following.


Kinematic rigidbodies
* zero mass
* can be animated by the user(!!!!!), but there will be only one-way interaction: dynamic objects will be pushed away but there is no influence from dynamics objects



Best of luck and remember you have to use the getWorldTransform callback of a subclassed Motionstate to set the object in the physical model. The body connected to that motion state must have:



body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); // It should be kinematic
body->setActivationState(DISABLE_DEACTIVATION); //It should do it's job each and every frame



Hope that helps!

uelkfr

27-07-2011 17:13:44

bool isDynamic = (mass = 0.f);

bool isDynamic = (mass == 0.f);