Friday, May 12, 2017

XNA 3rd Person Camera - pitch reverses when facing backwards?


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);
}

Answer



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);



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...