Set object rotation using a lookAt-Vector

I am looking for a way to get a Euler rotation using a vector which represents the direction an object is facing.
Basically the opposite of
//Get camera lookat axis
let vLookAt = new THREE.Vector3(0,0,-1).applyQuaternion(_camera.quaternion);
In addition to that, I would like to know if there is a way to describe said rotation without the use of the z component.

It’s not possible to derive a rotation in whatever representation (euler angles, quaternions, matrices) from just a single direction vector. Maybe the easiest way for you is to use Object3D.lookAt(). Since the method expects a target position (not direction), just add the direction vector to the current position. Something like this:

target.copy( object.position ).add( targetDirection );
object.lookAt( target );

For a 3D rotation, you need three angles (heading/pitch/bank) about mutually perpendicular axes.

I suggest you read chapter 8 “Rotation in Three Dimensions” of 3D Math Primer for Graphics and Game Development for more information about that topic.

3 Likes