Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js First Person Controls moves the camera all the time

The game I'm designing currently requires a first person controller and luckily Three.js offers that class as well.

However I can't stop the camera from flying around. I know that the mouse movement causes the fly because it happens as soon as I move the mouse. But reading the js code,I cant find the attribue which causes this movement. Here is how I initiate the controls:
controls = new THREE.FirstPersonControls(camera);
controls.movementSpeed = 0.1;
controls.lookSpeed = 0.001;
controls.lookVertical = true;

I do not want the view direction to change when I am not moving the mouse.

any idea ?

like image 278
ye9ane Avatar asked Jul 01 '13 13:07

ye9ane


2 Answers

Keep in mind that the FPS style mouse movement in webGL is usable rather only in a full screen mode. If an application runs in a standard windowed mode, the cursor is visible, and the application can not detect cursor movements that cross the edge of the window. This makes it impossible to look around in the FPS style (look movement stops when the cursors reaches the window edge).

This is probably the main reason why a PointerLockControls demo asks you to switch to the full screen mode.

With FirstPersonControls the look movement continues when the mouse reaches the edge. Such approach works well in the windowed mode.

like image 87
Jan Wrobel Avatar answered Nov 16 '22 02:11

Jan Wrobel


You might want to use the PointerLockControls instead

See an example here: https://github.com/mrdoob/three.js/blob/master/examples/misc_controls_pointerlock.html

like image 23
Chris Laarman Avatar answered Nov 16 '22 02:11

Chris Laarman