atsakir
22-05-2006 15:28:46
Hi all, I am trying to implement character motion on a terrain (simple mesh- not heightmap) using forces and a point & click interface. I raycast from a 3rd person camera onto the terrain body and get the target position. Now my main problem is tryng to change the orientation of my character towards this target point using setOmega until the angle between my character orientation and the target is 0.
here's what i've come up with so far which doesn't work as I want it to though
Anyone have any ideas on what I am doing wrong? I don't want to set rotation manually because I want to use the character ellipsoid body for collision with other world objects as well
here's what i've come up with so far which doesn't work as I want it to though
bool WalkCharacter::update (Real elapsedTime, Ogre::Vector3 target) {
body->unFreeze();
if (StateManager::Instance().getCurrentState() == MAINGAME){
Ogre::Vector3 pos;
Ogre::Quaternion orient;
body->getPositionOrientation(pos,orient);
Ogre::Vector3 walkdir = target-body->getPosition();
walkdir.y=0;
distCharTarget= sqrt(walkdir.squaredLength());
orientationToTarget = body->getPosition().getRotationTo(target);
Ogre::Vector3 vel = (walkdir.normalisedCopy()*speed)/elapsedTime;
Ogre::Radian charRotationY;
if (distCharTarget>sqrt(vel.squaredLength()))
{
Matrix3 target_orient_matrix;
Matrix3 char_orient_matrix;
orient.ToRotationMatrix(char_orient_matrix);
orientationToTarget.ToRotationMatrix(target_orient_matrix);
Yangle = Ogre::Math::ATan2 (*target_orient_matrix[0], *target_orient_matrix[2]);
charRotationY=Ogre::Math::ATan2 (*char_orient_matrix[0], *char_orient_matrix[2]);
if (Yangle.valueDegrees() > charRotationY.valueDegrees()) body->setOmega(Vector3(0,(1),0));
else if (Yangle.valueDegrees() < charRotationY.valueDegrees()) body->setOmega(Vector3(0,(-1),0));
else body->setOmega(Vector3(0,0,0));
body->setVelocity(vel);
handleAnimation(0);
return true;
}
}
return false;
}Anyone have any ideas on what I am doing wrong? I don't want to set rotation manually because I want to use the character ellipsoid body for collision with other world objects as well