Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My model rotates on it's own Y-axis regardless of where it is in the world. Here are the controls for the left ThumbStick:

UP (move model forward on Z-Axis) DOWN (move model backward on Z-Axis) LEFT & RIGHT (strafe to either side)

The problem is adjusting the direction the model's orientation UP and DOWN if the player should also rotate the player while moving forward or backwards.

An example what Im trying to achieve would be a car doing donuts. The car is always facing the current direction that it interprets as forward (or rear as backwards) in relation to it's local rotation.

Here is how Im calling the movement:

            // Rotate model with Right Thumbstick along X-Axis
            modelRotation -= pController.ThumbSticks.Right.X * mRotSpeed;

            // Move Forward
            if (pController.IsButtonDown(Buttons.LeftThumbstickUp))
            {
                modelPosition.Z -= -pController.ThumbSticks.Left.Y * speed;
            }

            // Move Backward
            if (pController.IsButtonDown(Buttons.LeftThumbstickDown))
            {
                modelPosition.Z += pController.ThumbSticks.Left.Y * speed;
            }
            // Strafe Left
            if (pController.IsButtonDown(Buttons.LeftThumbstickLeft))
            {
                modelPosition.X += -pController.ThumbSticks.Left.X * speed;
            }
            // Strafe Right
            if (pController.IsButtonDown(Buttons.LeftThumbstickRight))
            {
                modelPosition.X -= pController.ThumbSticks.Left.X * speed;
            }
            // DeadZone
            if (!pController.IsButtonDown(Buttons.LeftThumbstickUp) &&
                !pController.IsButtonDown(Buttons.LeftThumbstickDown) &&
                !pController.IsButtonDown(Buttons.LeftThumbstickLeft) &&
                !pController.IsButtonDown(Buttons.LeftThumbstickRight))
            {

            }
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Found the answer.

For those that run into the same problem, here it is to keep your 3d model facing the direction of travel/rotation (XBox360 controller):

            // Move Forward
            if (pController.IsButtonDown(Buttons.LeftThumbstickUp))
            {
                speedx = -(float)(Math.Sin(modelRotation)) * forwardSpeed;
                speedz = -(float)(Math.Cos(modelRotation)) * forwardSpeed;

                modelPosition += Vector3.Forward * speedz;
                modelPosition += Vector3.Left * speedx;
            }
share|improve this answer
    
If that's the solution you should take this as answer for the question. :) –  bryan226 Oct 8 '12 at 9:39
    
@bryan226 Thx for reminding me! lol :D –  ChocoMan Oct 9 '12 at 23:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.