I am currently developing an immersive VR web application using three.js. I have integrated the device orientation controls from the Google Cardboard three.js demo for camera navigation.
Now, I am looking to incorporate keyboard controls for additional functionality (e.g., using the Up arrow key to move forward). I have experimented with adjusting the camera's position along the x and z axes in response to key presses:
if (e.keyCode == '38') {
camera.position.set(0, 10, camera.position.z+4);
controls.target.set(
camera.position.x +4,
camera.position.y,
camera.position.z
);
effect.render(scene, camera);
...
However, my goal is to make the character move based on their viewing direction (e.g., pressing the Up arrow will move the character in the direction they are looking). Essentially creating a first-person view experience.
Has anyone successfully implemented this feature before? I attempted using the first person controls provided by three.js, but that removes the head tracking functionality crucial for a VR game.
Any insights or solutions would be highly valued. (Currently, my source code closely resembles the Google Cardboard three.js demo with added functionality to detect key inputs)