Search code examples
three.jspointerlock

Change look speed when using PointerLockControls


I'm trying out pointer lock in three.js via the examples, but I can't find much information on it. I'd like to show the user a text field in which they can manually enter their look speed (so the speed of the mouse).

Anyone knows how to do this? Can't seem to find how to increase or decrease the look speed.

In PointerLockControls.js, changing yawObject.rotation.y -= movementX * 0.002; pitchObject.rotation.x -= movementY * 0.002; does change the speed, but I can't seem to find how to update it in-game.


Solution

  • Modify your copy of PointerLockControls. First add

    this.speedFactor = 0.002;
    

    Then modify the lines you referenced like so;

    euler.y -= movementX * scope.speedFactor;
    euler.x -= movementY * scope.speedFactor;
    

    Now you can change the look speed dynamically:

    controls.speedFactor = 0.010;
    

    three.js r.120