(Quaternion based) Trouble moving foward based on model rotation

Posted by ChocoMan on Game Development See other posts from Game Development or by ChocoMan
Published on 2012-09-20T07:41:04Z Indexed on 2012/09/20 9:52 UTC
Read the original article Hit count: 327

Filed under:
|
|
|

Using quaternions, I'm having trouble moving my model in its facing direction. Currently the model moves can move in all cardinal directions with no problems. The problem comes when I rotate the move as it still travelling in the direction of world space. Meaning, if I'm moving forward, backward or any other direction while rotating the model, the model acts like its a figure skater spinning while traveling in the same direction.

How do I update the direction of travel proper with the facing direction of the model?

Rotates model on Y-axis:

        Yaw = pController.ThumbSticks.Right.X * MathHelper.ToRadians(speedAngleMAX);            
        AddRotation = Quaternion.CreateFromYawPitchRoll(yaw, 0, 0);
        ModelLoad.MRotation *= AddRotation;
        MOrientation = Matrix.CreateFromQuaternion(ModelLoad.MRotation);

Moves model forward:

        // Move Forward
        if (pController.IsButtonDown(Buttons.LeftThumbstickUp))
        {
            SpeedX = (float)(Math.Sin(ModelLoad.ModelRotation)) * FWDSpeedMax * pController.ThumbSticks.Left.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
            SpeedZ = (float)(Math.Cos(ModelLoad.ModelRotation)) * FWDSpeedMax * pController.ThumbSticks.Left.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
            // Update model position
            ModelLoad._modelPos += Vector3.Forward * SpeedZ;
            ModelLoad._modelPos += Vector3.Left * SpeedX;
        }

© Game Development or respective owner

Related posts about XNA

Related posts about c#