i'm trying to use this function of the bullet to control my player, but i'm having problem with the update position of the node, i try with some models and all don't touch the ground.
Tthis call the function addCharacter
Code: Select all
vector3df playerPos = this->Node->getPosition();
// vector3df playerScale = this->Node->getScale();
// calculate value for ccdThreshold
core::aabbox3d<f32> box = this->Node->getBoundingBox();
core::vector3df ext = box.getExtent();
std::cout << "Character Height - " << ext.Y << " | Width " << ext.Z << std::endl;
this->characterController = this->FalconeEngine->addCharacter( this->stepHeightPlayer,
&btVector3(playerPos.X,playerPos.Y,playerPos.Z),
(btScalar)ext.Z,
(btScalar)ext.Y);Code: Select all
btKinematicCharacterController* FPhysic::addCharacter( btScalar stepHeight,
btVector3 * characterPosition,
btScalar characterHeight,
btScalar characterWidth)
{
btPairCachingGhostObject* ghostObject= new btPairCachingGhostObject();
std::cout << "Character Width - " <<characterWidth << " | " << this->physicsWorldScaling << " | " << characterWidth * this->physicsWorldScaling << " | Height " << characterHeight * this->physicsWorldScaling << std::endl;
btConvexShape* characterShape = new btCapsuleShape( characterWidth * this->physicsWorldScaling,
characterHeight * this->physicsWorldScaling);
btTransform trans;
trans.setIdentity();
btScalar physicsWorldScaling2 = 0.1f;
trans.setOrigin(*characterPosition * this->physicsWorldScaling);
ghostObject->setWorldTransform(trans);
ghostObject->setCollisionShape(characterShape);
btKinematicCharacterController* character = new btKinematicCharacterController ( ghostObject,
characterShape,
stepHeight * this->physicsWorldScaling,
1);
this->gDynamicsWorld->addCollisionObject( ghostObject,
btBroadphaseProxy::CharacterFilter,
btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
this->gDynamicsWorld->addCharacter(character);
return character;
};
Code: Select all
///set the forward direction of the character controller
btVector3 walkDir(0,0,0);
if (gPlayerForwardBackward)
{
core::vector3df rot = Player->getNode()->getRotation();
core::matrix4 mat;
mat.setRotationDegrees(rot);
btVector3 forwardDir(mat[8],mat[9],mat[10]);
walkDir += forwardDir*gPlayerForwardBackward*0.1f;
}
if (gPlayerSideways)
{
core::vector3df rot = Player->getNode()->getRotation();
core::matrix4 mat;
mat.setRotationDegrees(rot);
btVector3 sideWays(mat[0],mat[1],mat[2]);
walkDir += sideWays*gPlayerSideways*0.1f;
}
Player->getCharacter()->setWalkDirection(walkDir);
//Atualiza Mundo da Physica
Engine->loopPhysicEngine();
btVector3 c = Player->getCharacter()->getGhostObject()->getWorldTransform().getOrigin()/0.1f;
core::vector3df pos (c.getX(),c.getY(),c.getZ());
Player->getNode()->setPosition(pos);