0

The function below works perfectly for orienting objects towards the user's cursor, if the object is centered at world origin, but it does not work otherwise.

function onMouseMove( e ) {
    var mouse3D = new THREE.Vector3(
        ( event.clientX / window.innerWidth ) * 2 - 1,
        - ( event.clientY / window.innerHeight ) * 2 + 1,
        0.5);

    eyes.forEach(function(element, index, array) {
        element.lookAt(mouse3D);
    })
}

How would I go about offsetting the lookat target (mousePosition3D) to work with non world origin objects? Is there a better way of getting a bunch of randomly placed objects orienting towards the user's cursor?

WestLangley
  • 102,557
  • 10
  • 276
  • 276
Pajama
  • 67
  • 4
  • Read http://stackoverflow.com/questions/13055214/mouse-canvas-x-y-to-three-js-world-x-y-z/13091694#13091694 and convert mouse coords to a 3D world point `pos`. Then call lookAt( pos ). – WestLangley Jun 22 '15 at 02:05
  • This only seems to work on the y axis. My object doesn't turn when I move mouseX, until I pass the object, then my object completely flips. – Pajama Jun 22 '15 at 02:17

0 Answers0