Custom ForceAndTorque Callback only called temporarily

cane_student

03-09-2008 19:32:19

Hi im a games dev student creating a game in OGRE for my final project.

I have been loving it so far, I have been getting through it at a good pace due to all the help and tutorials that are available.

This is the first problem that has caused me to need to ask for help and i would appreciate any given.

I have a customForceAndTorque callback that is defined once, when setting up the physics for the player.

Problem is i set a constant velocity on a rigid body and after a while it stops moving, similarly if i have an IF statement within the callback it only gets fired once.

e.g.

if(mWalking)
me->setVelocity(vel);

If the boolean value is true initially it performs it for a limited time, if it is false initially then changes to true during run-time it does not change the behaviour as it should.

Leading me to believe there is a problem when updating mWorld.


any thoughts????

thanks

Cane

walaber

03-09-2008 19:38:49

if the body stops moving, it will fall "asleep", and the force callback will no longer be called.

you need to call setSleepState(0) (i think that's the function name) to re-awalen the body, and then the callback will be called again.

if you only have a few bodies like this, you can set auto sleep to zero on initialization, and the body will never fall asleep.


the new version of Newton 2.0 will always call the callbacks, no matter what.

cane_student

03-09-2008 21:35:14

I tried setting auto-freeze to make it application controlled and this failed to make any changes the same still happens it moves to a certain poisition then stops.

I think also it is not time related, i speed up the move and the ninja move then stops in the same place everytime...

here is the callback code



void Player::entityForceCallback(OgreNewt::Body* me)
{
Ogre::Real mass;
Ogre::Vector3 inertia;

mPos = me->getOgreNode()->getPosition();

me->getMassMatrix(mass, inertia);

mOmega = me->getOmega();

me->addForce(Ogre::Vector3(50.0,0.0,0.0));

}

cane_student

04-09-2008 12:04:22

After more experimentation, I have discovered that there seems to be bounds around the physics world.

If anything is +100 or -100 units away from the the origin in the Y a standard force callback will not act on it.

similaraly in the X the bounds are +115 or - 115.

Has anybody else experienced this, is there a fucntion which determines the size of the physics world?

nord666

04-09-2008 12:12:58

Hi,

There's a function to set the size of the world:

mWorld->setWorldSize( /* choose between AABB or 2 vector to set the size*/ );

cane_student

04-09-2008 12:32:10

Thanks alot mate, has solved my issues...

I feel like i need a slap in the face for not solving it tho :shock:

micken

06-09-2008 14:44:46

For debugging purposes it is always a good idea to set a LeaveWorldCallback that prints which body has left the world so that there will be no confusion when something leaves the world. Having this callback is a good idea in any case because you will always want to deal with bodies leaving the world.