I have a three.js program, where when I press the "w" key it moves the camera forward.
if (keys.indexOf(playerControls["forward"]) != -1) {
camera.translateZ(-0.1);
}
However, I want the camera to not move vertically at all, but just horizontally (x and z axes move when "w" is pressed, but y axis is ignored). How would I be able to do this? (without a bunch of trig)
The translateZ is important to move the camera in the direction you're facing, but you can easily fix the Y position by correcting it after each movement:
const camHeight = 5;
if (keys.indexOf(playerControls["forward"]) != -1) {
camera.translateZ(-0.1);
camera.position.y = camHeight;
}