[SOLVED] Raycaster on mouse click laggs an action behind

This problem occurs when the canvas if not full screen. You can use the canvas bounds instead of the window width/height like so


  var canvasBounds = renderer.domElement.getBoundingClientRect();

  mouse.x = ( ( event.clientX - canvasBounds.left ) / ( canvasBounds.right - canvasBounds.left ) ) * 2 - 1;
  mouse.y = - ( ( event.clientY - canvasBounds.top ) / ( canvasBounds.bottom - canvasBounds.top) ) * 2 + 1;

  raycaster.setFromCamera( mouse, camera );

http://jsfiddle.net/rv41kzuy/38/

1 Like