Turning lose its effect after adding a force

lullideath

06-09-2006 22:04:02

i am trying to get the enemy turn to the player and then run towards the player, here is the all the stuffs I have for turning, which works great alone:

Ogre::Vector3 mDirection = player->getWorldPosition() - mBody->getGlobalPosition();
mDirection.y = 0;
mDirection.normalise();
Ogre::Vector3 src = mBody->getGlobalPosition() * Ogre::Vector3(0,0,-1);
Ogre::Quaternion quat = src.getRotationTo( mDirection );
mBody->mNode->setOrientation(quat);

after that, I want the enemy run to the player, so i added a simple force after the last line of the turning code above:

mBody->addForce(mDirection*speed);

now, the enemy no longer turn its body anymore - it faces the original direction all the time, while moving towards the player...

Any help would be great!!!!!!!!!!!!!!
thanks a lot!!!
lullideath

lullideath

06-09-2006 22:28:01

hi, a friend just found the problem in the code! all i need to do is replacing:
mBody->mNode->setOrientation(quat);
to
mBody->setGlobalOrientation(quad);

Now, everything works perfect!!!
lullideath

betajaen

06-09-2006 22:46:26

That'll work.

However, if it's an enemy a human enemy for example. It might be better to use a character for that. :D