My character controller is working

Unfortunately I've some problems with the collisions, nothing serious, but the movement seems less fluid than the original character controller. If someone could give me a tip of what could cause such problem, it would be a start.
Here goes the code:
OgreCharacterController.zip
And here goes some examples how to apply some movements:
Code: Select all
// Do this at each update fase ( before or after doing the stepSimulation )
btVector3 movement = btVector3( 0.0, 0.0, 0.0 );
movement += applyMovement( dt );
movement += applyGravity( dt );
// m_character is my character controller object
m_character->setMoveTranslation( movement );
The function to move forward and/or strafe
Code: Select all
btVector3 applyMovement( float deltaTime ) {
// Rotate character
if( gLeft ) {
btMatrix3x3 orn = m_ghostObject->getWorldTransform().getBasis();
orn *= btMatrix3x3( btQuaternion( btVector3( 0, 1, 0 ), 0.01 ) );
m_ghostObject->getWorldTransform ().setBasis( orn );
}
if( gRight ) {
btMatrix3x3 orn = m_ghostObject->getWorldTransform().getBasis();
orn *= btMatrix3x3( btQuaternion( btVector3( 0, 1, 0 ), -0.01 ) );
m_ghostObject->getWorldTransform().setBasis( orn );
}
// Move character
btTransform transform = m_ghostObject->getWorldTransform();
btVector3 forwardDir = transform.getBasis()[2];
forwardDir.setY( 0.0 );
forwardDir.normalize();
btVector3 strafeDir = transform.getBasis()[0];
strafeDir.setY( 0.0 );
strafeDir.normalize();
btVector3 walkDirection = btVector3( 0.0, 0.0, 0.0 );
if( gForward ) {
walkDirection += forwardDir;
}
if( gBackward ) {
walkDirection -= forwardDir;
}
btScalar walkVelocity = btScalar( 1.1 ) * 40.0; // 4 km/h -> 1.1 m/s
btVector3 walkMovement = walkDirection * ( walkVelocity * deltaTime );
return walkMovement;
}
The function to simulate gravity
Code: Select all
btVector3 applyGravity( float deltaTime ) {
btVector3 fallMovement = btVector3( 0.0, 0.0, 0.0 );
if( isGrounded() == false ) {
btScalar fallVelocity = -20 * deltaTime;
fallMovement.setY( fallVelocity );
}
return fallMovement;
}
The function to verify if we are on solid ground
Code: Select all
bool isGrounded() {
return ( m_character->getCollisionFlags() & Below ) != 0;
}
All those functions where used with the CharacterDemo project. I didn't implemented the jump, warp or reset function into the character controller class, because it depends on how the customer want the character to behave. For example, the jump function could be implemented in several ways:
- using a fall acceleration and the jump height;
using a jump speed and a fall speed;
using a jump acceleration and a fall acceleration;
etc...
Any idea/opinion is welcome.
You do not have the required permissions to view the files attached to this post.