I am currently working on implementing a basic camera movement system in WebGL using JavaScript and the keyboard to control the camera's movement along the X and Y axes. However, I am facing an issue where the camera moves in world coordinates rather than relative to its own X and Y axes, resulting in a lack of realistic movement and inconsistencies based on the camera's orientation.
Below is some code snippet I have been using (I am unsure if the "updateprojectionmatrix" line is necessary in this context):
var arrow = { left: 37, up: 38, right: 39, down: 40 };
var delta = 100;
switch (event.which) {
case arrow.left:
camera.position.x = camera.position.x - delta;
camera.updateProjectionMatrix();
break;
case arrow.up:
camera.position.y = camera.position.y + delta;
camera.updateProjectionMatrix();
break;
case arrow.right:
camera.position.x = camera.position.x + delta;
camera.updateProjectionMatrix();
break;
case arrow.down:
camera.position.y = camera.position.y - delta;
camera.updateProjectionMatrix();
break;
}