movement with first person camera -moves like sliding on ice

dudeabot

07-02-2008 02:04:16

hi im having a problem with movement and first person camera

im using a customForceandTorquecallback for the camera body, as advised by numerous post on the forums

my implementation is clearly based on the one from this topic:

http://www.ogre3d.org/phpBB2addons/view ... son+camera

the problem is, when i move the player it wont stop instantanially (which is expected but not wanted) i searched the forum and seem similar threads with not clear solution.

I tried adding a contrary force as suggested on one of those threads, but the main problem is, how much force would i need to add, and when tell the callback to stop...

im using 0.8 for kinet and dynamic friction, it did help, but the character still slides :(

maybe addForce isnt the right way to go for this problem, anyone got suggestions?

albino

20-02-2008 06:36:18

hi,

i used this code, works pretty well i think

//make sure player doesnt fell asleep
me->setAutoFreeze(0);

Ogre::Vector3 currentVel = me->getVelocity();
Ogre::Vector3 force = Ogre::Vector3::ZERO;

Ogre::Vector3 curOmega = me->getOmega();
Ogre::Vector3 torque = Ogre::Vector3::ZERO;

Ogre::Vector3 inertia;
Ogre::Real mass;

me->getMassMatrix( mass, inertia );

//accelration based on target velocity and current velocity
Ogre::Vector3 accel = (( targetVel - currentVel ) / me->getWorld()->getTimeStep());
//angular acceleration based on current omega and target omega
Ogre::Vector3 angular = (targetOmega- curOmega) / me->getWorld()->getTimeStep();

//force and torque calculations
torque = angular * inertia;
force = mass * accel;

//gravity needed
force.y = -9.81 * mass;

//add them to body
me->addForce( force );
me->addTorque(torque);