I'm currently working on a first person 3D game in javascript using Three.js. I'm using PointerLockControls to control camera movement, and for some reason, the camera seems to be jumping around randomly on the Y axis. It's not noticable in the game itself but if I print out camera.position in my render loop, it changes sporadically. I'm using WASD to call controls.moveForward() and controls.moveRight() which shouldn't affect Y position (I think, correct me if I'm wrong) but it changes nonetheless. This is the code of interest:
var controls = new THREE.PointerLockControls(camera, document.body);
document.onclick = function () {
controls.lock();
}
function loop() {
if (wDown) {
controls.moveForward(0.1);
}
if (sDown) {
controls.moveForward(-0.1);
}
if (dDown) {
controls.moveRight(0.1);
}
if (aDown) {
controls.moveRight(-0.1);
}
// printing out camera position
console.log(camera.position);
renderer.render(scene, camera);
requestAnimationFrame(loop);
}
Edit: I should note, the Y position only changes when I move using WASD.