5

Edit: Looks like the problem is for touchpad not mouse.

Goal: To be able to respond to mouse movements even when key(s) is being pressed.

I want to modify PointerLockControls of Three.js so that: if user moves mouse when pressing W, then the camera should continue to move forward and the direction of camera should also change according to mouse movement. This is not happening in normal scenario. Here are the listeners:

Listener for mousemove event:

var onMouseMove = function ( event ) {
    var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
    camera.rotation.y-=movementX*0.002;
  };

Listener for keydown event:

var onKeyDown = function ( event ) {
    
        case 38: // up
        case 87: // w
            moveForward = true;
            break;
        //keys: a, s, d are handled similarly

        case 32: // space
            if ( canJump === true ) velocity.y += 10;
            canJump = false;
            break;
   }

Listener for keyup event:

var onKeyUp = function(event){
        case 38: // up
        case 87: // w
            moveForward = false;
            break;
}

I found that, if I hit spacebar when pressing W, then, the player continues to move forward AND responds to mouse movement. This is the effect I want (but it should work even without hitting spacebar).

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
coolscitist
  • 3,317
  • 8
  • 42
  • 59
  • Is it possible that you are using an older version of three.js? I just ran the example http://mrdoob.github.com/three.js/examples/misc_controls_pointerlock.html in full screen mode and what happens is exactly the opposite of what you describe. When pressing "W", the camera continues to move forward and the direction of the camera changes according to mouse movement. When the space bar is pressed then there is only vertical movement (even when pressing W). – gaitat Mar 24 '13 at 07:19
  • Oh.... when I use touchpad of my laptop, then the behaviour is as I described. But when I use the mouse itself, then the behaviour is as you described it. hmm.... looks like a fresh new problem... – coolscitist Mar 24 '13 at 12:07
  • No my touchpad has the same as mouse behavior. – gaitat Mar 24 '13 at 12:45
  • That's really odd. What should be my next step to counter this problem? – coolscitist Mar 24 '13 at 13:14
  • 1
    Debugging. Start with the original PointerLockControls.js file and make sure that in the onMouseMove() call, the values of movementX and movementY do get modified. The other variable to check is velocity. – gaitat Mar 24 '13 at 13:29
  • Mousemove event is not fired or at least is not "listened to" when key is being pressed. Velocity, as expected, changes while pressing "w" whether the mouse is moved or not. – coolscitist Mar 24 '13 at 14:20
  • Sorry I dont know what to tell you. I just verified it works on my laptop both using Firefox and Chrome (latest versions) with three.js r57. Maybe you can post it as an issue at https://github.com/mrdoob/three.js/issues – gaitat Mar 24 '13 at 14:43
  • But is it a three.js problem? This could be a problem in driver of touchpad itself. Anyway, I will post the issue as soon as I reach my home and get my hands on laptop. – coolscitist Mar 25 '13 at 01:46

1 Answers1

2

Usually Operating Systems disable the touchpad when typing. You should find an option to toggle this somewhere on your OS settings.

mrdoob
  • 19,334
  • 4
  • 63
  • 62