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.

I have a 3rd person camera which rotates around the Y axis fine (yaw) and when I am facing forward (0, 0, -1) moving the mouse up moves the camera up and down great. But the more I turn the player and camera the the less the camera moves up and down until I get to 90 degrees where it almost stay still and at 180 it moving the mouse up moves the camera down!

Any ideas? How should I be calculating camera pitch? The player only yaws - it does not roll or pitch. The camera yaws and pitches. The cameras update method looks like:

    public void Update(Vector3 playerPos, float pitch, float yaw)
    {
        Matrix rotation     = Matrix.CreateRotationY(yaw) * Matrix.CreateRotationX(pitch);
        Vector3 newOffset   = Vector3.Transform(offsetAmount, rotation);

        cameraPos   = playerPos + newOffset;
        View        = Matrix.CreateLookAt(cameraPos, playerPos, Vector3.Up);
        Projection  = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Constants.AspectRatio, Constants.NearClip, Constants.FarClip);
    }
share|improve this question

1 Answer 1

up vote 5 down vote accepted

Sounds alot like your Matrices are being multiplied in the wrong order. Try reversing the order of Multiplication to:

Matrix rotation = Matrix.CreateRotationX(pitch) * Matrix.CreateRotationY(yaw);

share|improve this answer

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.