deshan
11-01-2010 03:59:28
Hi
I am writing a code to rotate(actuall yaw) the body A to direction of the bodyB. Code works but sometimes it rotates to unexpected direction. What happen is body rotate upside down(pitch).
calling to rotate
If you can see this is wrong please tell me. I have noticed that this happens when player position is exactly same or very close enemy position.
I am writing a code to rotate(actuall yaw) the body A to direction of the bodyB. Code works but sometimes it rotates to unexpected direction. What happen is body rotate upside down(pitch).
Ogre::Quaternion EnemyCharacter::playerFoundRotationCalculation()
{
Vector3 enemyPosition = enemyBody->getGlobalPosition().as<Ogre::Vector3>();
Vector3 playerPosition = playerBody->getGlobalPosition().as<Ogre::Vector3>();
enmPosition.y = 0;
playerPosition.y = 0;
Vector3 directionToPlayer = (playerPosition - enemyPosition);
directionToPlayer.normalise();
Ogre::Quaternion enemyOrientation = enemyBody->getGlobalOrientationQuat().as<Ogre::Quaternion>();
Vector3 src = enemyOrientation * Ogre::Vector3::UNIT_X;
Ogre::Quaternion quat = src.getRotationTo(directionToPlayer);
return quat * enemyOrientation;
}}
calling to rotate
enemyBody->setGlobalOrientationQuat(playerFoundRotationCalculation());
If you can see this is wrong please tell me. I have noticed that this happens when player position is exactly same or very close enemy position.