Movement Error

josericardo_jr

22-11-2006 11:32:15

Hi people,

I'm getting crazy whith this problem.
I created a character and a capsule for his collision. When I started my application, my character start falling because of the gravity force but after some time (about 2 seconds) it appear in other place without any external force. Here's my forceCallback:


void _ForceAndTorque( OgreNewt::Body *me )
{
CPlayer *player = (CPlayer*) me -> getUserData();
player -> ForceAndTorque( me );
}

void ForceAndTorque( OgreNewt::Body *me )
{
Ogre::Real mass;
Ogre::Vector3 inertia;
Ogre::Vector3 currentVelocity;
Ogre::Vector3 force;

me -> getMassMatrix( mass, inertia );
currentVelocity = me -> getVelocity();

if ( mTimeSinceLastFrame > 0 )
{
force = ( mass * ( ( mDesiredVel - currentVelocity ) / mTimeSinceLastFrame ) );
force.y = 0;
me -> addForce( force );
}

std::ostringstream buf;
buf << "CurrentVel: X = " << currentVelocity.x << " Y = " << currentVelocity.x << " Z = " << currentVelocity.x;
Ogre::LogManager::getSingleton().getDefaultLog() -> logMessage( buf.str() );


me -> addForce( Ogre::Vector3( 0, -10.0, 0 ) * mass );

}


And it's my frameStart:



bool inputed = input -> isKeyDown( Ogre::KC_W ) || input -> isKeyDown( Ogre::KC_A ) ||
input -> isKeyDown( Ogre::KC_S ) || input -> isKeyDown( Ogre::KC_D );

mTimeSinceLastFrame = elapsedTime;
mDesiredVel = Ogre::Vector3::ZERO;

if ( inputed )
{
mCurrentVel += 1;

if ( mCurrentVel >= 30 )
mCurrentVel = 30;


if ( input -> isKeyDown( Ogre::KC_W ) )
mDesiredVel.z = -1;

if ( input -> isKeyDown( Ogre::KC_S ) )
mDesiredVel.z = 1;

if ( input -> isKeyDown( Ogre::KC_A ) )
mDesiredVel.x = -1;

if ( input -> isKeyDown( Ogre::KC_D ) )
mDesiredVel.x = 1;

mDesiredVel *= mCurrentVel;
mDesiredVel = mBody -> getOgreNode() -> getOrientation() * mDesiredVel;
}
else
{
mCurrentVel = 0;
mDesiredVel = Ogre::Vector3::ZERO;
}
}


Does somebody knows why this problem occour?

Thanks a lot.

Ricardo