kintaro
16-03-2006 17:58:06
Hi, below there is a piece of code to move a character that has an box as primitive object phisics, and it has setStandardForceCallback().
When the character is not moving, the gravity act over it normally, but when I moving it in any direction, the gravity does not act, till I stop moving the character.
How can fix it?
Note: Till now only foward moving has walking animation, I decided to put animation in other directions after fix the gravity problem.
Thanks for help
mAnimationState->addTime( evt.timeSinceLastFrame );
Vector3 trans, strafe, vec;
Quaternion quat;
quat = msnEnt->getOrientation();
vec = Vector3(0.0,0.0,-0.5);
trans = quat * vec;
vec = Vector3(0.5,0.0,0.0);
strafe = quat * vec;
mInputDevice->capture();
msnCam->pitch( Degree(mInputDevice->getMouseRelativeY() * -0.5) );
msnCam->yaw( Degree(mInputDevice->getMouseRelativeX() * -0.5), SceneNode::TS_WORLD );
ent_body->unFreeze();
if (mInputDevice->isKeyDown(Ogre::KC_UP) || mInputDevice->isKeyDown(Ogre::KC_W))
{
ent_body->setVelocity( (trans * 10.0) );
// Set walking animation
if( mAnimationState->getAnimationName() == "Idle1" )
{
mAnimationState->setTimePosition( 0.0f );
mAnimationState->setEnabled( false );
}
mAnimationState = mEntity->getAnimationState( "Walk" );
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
}
if (mInputDevice->isKeyDown(Ogre::KC_DOWN) || mInputDevice->isKeyDown(Ogre::KC_S))
{
ent_body->setVelocity( (trans * -1 * 10.0) );
}
if (mInputDevice->isKeyDown(Ogre::KC_LEFT) || mInputDevice->isKeyDown(Ogre::KC_A))
{
ent_body->setVelocity( (strafe * -1 * 10.0) );
}
if (mInputDevice->isKeyDown(Ogre::KC_RIGHT) || mInputDevice->isKeyDown(Ogre::KC_D))
{
ent_body->setVelocity( (strafe * 10.0) );
}
if (mInputDevice->isKeyDown(Ogre::KC_PGDOWN))
{
Ogre::Vector3 dir(0,-1,0);
ent_body->setVelocity( (dir * 10.0) );
}
if (mInputDevice->isKeyDown(Ogre::KC_PGUP))
{
Ogre::Vector3 dir(0,1,0);
ent_body->setVelocity( (dir * 10.0) );
}
When the character is not moving, the gravity act over it normally, but when I moving it in any direction, the gravity does not act, till I stop moving the character.
How can fix it?
Note: Till now only foward moving has walking animation, I decided to put animation in other directions after fix the gravity problem.
Thanks for help