Moving a Character (Quaternion problem) (**SOLVED)

hoffhoff

09-06-2006 02:30:49

Hello,
I start making a game using Newton+Irrlicht, and then I could move it by applying to the body a force, like:
force.X = 100*sin(mesh->getrotation().Y));
force.Z = 100*cos(mesh->getrotation().Y));

Well, now I am moving to Ogre, because it looks very better than Irrlicht, but I donĀ“t know how to make the movement now. I read some documents of Quaternions (even the math book they sugest us to read), but could not understand it.
Can anybody tell me how I can apply the forces correctly, for to make the mesh moves forward?

Thanks!

walaber

09-06-2006 03:31:38

if your player "faces" in the -Z direction, you can do this:


Vector3 globalFaceVec = playerNode->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;

// this is now a unit vector in global space, pointing in the direction the player is "facing". if you want to remove the Y component, do the following:
globalFaceVec.y = 0.0f;
globalfaceVec.normalise();

// now apply the force.
Vector3 force = globalFaceVec * forceMagnitude;

hoffhoff

09-06-2006 14:07:01

It is working!
walaber, thanks again!

You are my hero =]