Veggieto
11-09-2012 00:23:09
Hello everyone, I'm using Ogre 1.74 with the ogreBullet libraries and I'm trying to implement a Character Controller.
Everything works more or less fine, with the exception that applying a force to the main character to make him move not only will actually make him move to the correct direction, but will also (and I really have no idea why atm) make him rotate a little as if the force wasn't actually applied on the center of mass.
I'll post the relevant part of the code here :
Inizialization of the main character :
WASD Implementation :
FrameStarted code function
Am I doing something terribly wrong?
Thanks in advance for any help!
Everything works more or less fine, with the exception that applying a force to the main character to make him move not only will actually make him move to the correct direction, but will also (and I really have no idea why atm) make him rotate a little as if the force wasn't actually applied on the center of mass.
I'll post the relevant part of the code here :
Inizialization of the main character :
Ogre::Vector3 size = Ogre::Vector3::ZERO;
Ogre::AxisAlignedBox boundingB = ent->getBoundingBox();
size = boundingB.getSize(); size /= 2.0f; // only the half needed
size *= 0.96f; // Bullet margin is a bit bigger so we need a smaller size
// (Bullet 2.76 Physics SDK Manual page 18)
// after that create the Bullet shape with the calculated size
sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size);
// and the Bullet rigid body
defaultBody = new OgreBulletDynamics::RigidBody("MainCharaRigid", mWorld);
defaultBody->setShape( _charaNode,
sceneBoxShape,
0.6f, // dynamic body restitution
0.2f, // dynamic body friction
1.0f, // dynamic bodymass
_charaNode->getPosition(), // starting position of the box
Ogre::Quaternion(0,0,0,1));// orientation of the box
/** Disabling model rotation, having your character tumbling around is no good! **/
defaultBody->getBulletRigidBody()->setAngularFactor(btVector3(0,1,0));
defaultBody->disableDeactivation();
WASD Implementation :
switch(e.key)
{
case OIS::KC_W:
_direction += Ogre::Vector3(0,0,0.10);
break;
case OIS::KC_A:
_direction += Ogre::Vector3(0.10,0,0);
break;
case OIS::KC_S:
_direction += Ogre::Vector3(0,0,-0.10);
break;
case OIS::KC_D:
_direction += Ogre::Vector3(-0.10,0,0);
break;
FrameStarted code function
...
defaultBody->applyForce(_direction, Ogre::Vector3(0,0,0));
mWorld->stepSimulation(evt.timeSinceLastFrame);
Am I doing something terribly wrong?
Thanks in advance for any help!