i've implemented a threejs keyboard control function that works fine as long as the camera is facing north, east or west direction, when it turns south, south-east, or south-west the controls reverse themselves
if(controls["KeyW"]){ // w
camera.position.x -= Math.sin(camera.rotation.y) * player.speed;
camera.position.z -= -Math.cos(camera.rotation.y) * player.speed;
}
if(controls["KeyS"]){ // s
camera.position.x += Math.sin(camera.rotation.y) * player.speed;
camera.position.z += -Math.cos(camera.rotation.y) * player.speed;
}
if(controls["KeyA"]){ // a
camera.position.x += Math.sin(camera.rotation.y + Math.PI / 2) * player.speed;
camera.position.z += -Math.cos(camera.rotation.y + Math.PI / 2) * player.speed;
}
if(controls["KeyD"]){ // d
camera.position.x += Math.sin(camera.rotation.y - Math.PI / 2) * player.speed;
camera.position.z += -Math.cos(camera.rotation.y - Math.PI / 2) * player.speed;
}
if(controls["Space"]) { // space
if(player.jumps) return false;
player.jumps = true;
player.velocity = -player.jumpHeight;
}
}
to better help you understand the problem i've been facing here's a link to my website, my guess is that the sin and cos revserse their values after a 180 rotation