Follow up question. I’ve this part of code now to listen for arrow inputs
canvas.addEventListener(“keydown”, (e)=>{
//if left arrow is pressed
if(e.keyCode == 37) {
camera.cameraRotation.y -= 0.05;
}
//if right arrow is pressed
else if(e.keyCode == 39) {
camera.cameraRotation.y += 0.05;
}
})
This works, but while holding the keydown for a continuous rotation, that rotation is not very smooth (which is expected behavior with this type of implementation I guess). Is there a way to smooth things out?
You should take the time between frames in accounts an debounce the events. Basically only turn once per frame as there is no reason to do more and use engine.deltaTime to know how much you should turn to simulate a constant rotation speed. With vector the function would be a lerp and a slerp for quaternion interpolation.
This is an old topic but I got confused reading it so I figured I’d leave a note. I also wanted to have WASD to move the cam and arrows to rotate it. Switching move controls to WASD is as shown in the initial post, as for adding rotation control via arrow keys, have a look at the FreeCameraKeyboardRotateInput as detailed in Customizing Camera Inputs | Babylon.js Documentation. But do not remove the FreeCameraKeyboardMoveInput.