freezed body

sisqosama

16-11-2009 02:19:27

hello all,
i'm doing my on character controller that seems to begin to work, finally. But there is one problem, after a small amount of time (4-5 seconds), my character is freezed, although I added the code to prevent that :

body->setAutoSleep(0);

I have a floor under my character, I also have my custom force callback :

void Hero::ForceCallback(OgreNewt::Body *body, float timeStep, int threadIndex)
{
body->unFreeze();

Hero* linkedHero = Ogre::any_cast<Hero*>(body->getUserData());

Ogre::Real mass;
Ogre::Vector3 inertia;
body->getMassMatrix(mass, inertia);

Ogre::Vector3 vVelocity = Ogre::Vector3(0, 0,0);

if(bUp)
vVelocity.x = 2.0f;

if(bDown)
vVelocity.x = -2.0f;

if(bRight)
vVelocity.z = 2.0f;

if(bLeft)
vVelocity.z = -2.0f;

vVelocity *= mass;
body->addLocalForce(vVelocity, Ogre::Vector3(0,0,0));

Ogre::Vector3 gravity = Ogre::Vector3(0, -9.8,0) * mass;
body->addForce(gravity);

}



Here is how I setup my physic body :


OgreNewt::CollisionPrimitives::Ellipsoid *elicol = new OgreNewt::CollisionPrimitives::Ellipsoid(mWorld, m_pSceneNode->getScale(), iCollisionID);
OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(elicol);
body = new OgreNewt::Body( mWorld, col, m_type);
body->attachNode( m_pSceneNode );
body->setMaterialGroupID( m_bodyMat );

Ogre::Real mass = 50.0;
Ogre::Vector3 inertia, centerOfMass;
elicol->calculateInertialMatrix(inertia, centerOfMass);

inertia*=mass;

body->setMassMatrix( mass, inertia );
body->setCenterOfMass(centerOfMass);

OgreNewt::BasicJoints::UpVector* joint = new OgreNewt::BasicJoints::UpVector(mWorld, body, Ogre::Vector3::UNIT_Y);

// initial position
body->setPositionOrientation( m_pSceneNode->getPosition(), Ogre::Quaternion::IDENTITY );
body->setAutoSleep(0);

body->setCustomForceAndTorqueCallback<Hero>( &Hero::ForceCallback, this );


Has anyone had this problem before?

prchakal

18-11-2009 05:00:34

This happen with me too.

Do you solve it?

sisqosama

19-11-2009 01:12:12

yeah, I'm a little ashamed to say this but... em... I forget to set the newton world size.


AxisAlignedBox entityAABB = ent->getWorldBoundingBox(true);
mWorld->setWorldSize(entityAABB);


with ent the world entity for me but for you, any size you want. Since I hadn't set it, my character was moving out of the physical world and wasn't updated...