I ve been trying to use the btKinematicController, and I have a weird problem I cant figure out by myself. The thing is, apart from all the known issues I ve read about the kinematic cc, it seems Im doing something wrong because when I try to move it its framerate dependant. Im making a game with Ogre and bullet and when I set the vsync option on the character moves much faster, what tells me it isnt framerate independant I guess.
The code I use to move it is something like this, I ve simplified it a lot since a have more stuff in there, but the base is that:
Code: Select all
//the loop
void GameState::update(double timeSinceLastFrame)
{
//get the player input
getInput();
//update the Player
Player->update(timeSinceLastFrame);
//update bullet world (the physics manager is just a wrapper to initialize bullet and keep
//some variables and deal with collision detections
m_pPhysicsMgr->m_pWorld->stepSimulation(timeSinceLastFrame*0.001, 2); //timeSincelastframe is in ms
}
void GameState::getInput()
{
float deltaTime = m_FrameEvent.timeSinceLastFrame/1000;
Ogre::Vector3 movementDirection = Ogre::Vector3::ZERO;
if(OgreFramework::getSingletonPtr()->m_pKeyboard->isKeyDown(OIS::KC_A))
movementDirection = movementDirection + Ogre::Vector3::NEGATIVE_UNIT_X ;
//... I do the same with each key that moves the character
Player()->setMovementVector(movementDirection);
}
void Player::setMovementVector(Ogre::Vector3 movementDir){
Ogre::Vector3 goalDirection = Ogre::Vector3::ZERO;
//I do stuff to get the direcciont depending the camera position
goalDirection += movementDir.z * m_pCamera->m_pCameraNode->_getDerivedOrientation().zAxis();
goalDirection += movementDir.x * m_pCamera->m_pCameraNode->_getDerivedOrientation().xAxis();
goalDirection.normalise(); // and then normalise that vector
float characterMovSpeed = 25;
m_MovementVector = goalDirection * characterMovSpeed; //vector3 member, keeps the movemente vector
//this is a Player member that keeps a pointer to the kinematicController
m_pCharController->setMovementVector(movementVector);
}
//called each frame
void Player::update(double timeSinceLastFrame){
//timeSinceLastFrame is in miliseconds
Ogre::Vector3 moveVector = m_MovementVector*(timeSinceLastFrame/1000)
//member pointer to the kinematicCharController
m_pCharacterC->setWalkDirection(BtOgre::Convert::toBullet(moveVector));
//I update the character node (the mesh and so forth) according to the characterController position
m_pCharacterNode->setPosition( (BtOgre::Convert::toOgre
( m_ghostObject->getWorldTransform().getOrigin() ) ) );
}
Thanks guys, you re the best.