I am trying to build a camera class, though I am running into a problem. When I move the camera above/below, and try to move towards the ground, I am moved off in what seems to be about 45 degrees in the YZ plane. Movement around the XZ plane seems fine. I do not see this effect when I am facing the cube from the side, it's likely just unnoticeable.

Here is the trig I'm applying:

public void moveForward(float amount)
    position.x -= amount * Math.sin(Math.toRadians(rotation.y));
    position.y += amount * Math.sin(Math.toRadians(rotation.x));
    position.z += amount * Math.cos(Math.toRadians(rotation.y));

public void apply()

    Matrix4f.rotate((float) Math.toRadians(rotation.x), new Vector3f(1, 0, 0), vMat, vMat);
    Matrix4f.rotate((float) Math.toRadians(rotation.y), new Vector3f(0, 1, 0), vMat, vMat);
    Matrix4f.rotate((float) Math.toRadians(rotation.z), new Vector3f(0, 0, 1), vMat, vMat);

    Matrix4f.translate(position, vMat, vMat);

I've tried using the 3D polar to component formulas instead of 2D. I've also tried swapping the cos/sin of various calls, all to less success.

For clarity, my intention is to be able to rotate any direction, and have movement operate along the cameras local Z axis.

How can I correct this?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.