How would you implement movement on a camera in order to always move it on X and Z coordinates, and if the camera has pitch yaw or roll it still moves only in those coordinates and doesn't fly up?
Anytime you applied a positional change (translation) to the camera, you would flatten that vector out.
Let's say in a non-restricted situation, where the camera could move along the Y-axis, that you have a movement vector like this:
Just remove the Y component.
I would recommend making your mutator for your camera class do this, or make a helper function.
If you have a class for your camera, I would use a mutator:
If you don't have a class for your camera, I would write a static utility method to call anytime you moved your camera:
Using this helper function with our original code:
You can make your helper function more efficient by passing by reference
If you use the version above that passes by reference, you'll need to call the method differently
Note that this is exactly what Tetrad's comment in your original question was referring to.
In a first person camera, you can move the camera forward by adding the
To move the camera left or right, you add/subtract the cross product of your vector with
Here's the code using libgdx:
you can achieve it using a dummy box, create a dummy box and attach camera as it's child. then whenever you want to move camera, you just have to move the dummy box, if you want to rotate camera left and right you also have to rotate the dummy box but for other axis rotations you will have to rotate camera itself.