mrdoob/three.js — Issue #1204: Third person look; Rotate center object to look in mouse direction.
Author: Bartinger
Created: 2012-01-28 00:04:00+00:00
State: open

Hello,
I really love Three.js, it's an awesome library.

My question is, how can I rotate an object so that it always looks in the mouse direction. Like in a third person shooter. I'm sorry I'm not that good in math :) My code

```javascript
//mouseMove event
mouse3D = new THREE.Vector3(
( event.clientX / window.innerWidth ) * 2 - 1,
- ( event.clientY / window.innerHeight ) * 2 + 1,
0.5 );

//some unimportant code and functions

//main loop
var angle = Math.atan2(mouse3D.z-box.position.z, mouse3D.x-box.position.x);
box.rotation.y = angle;