Rotate an object towards another object

Hi. I am new to three js. I was wondering if there is a way to rotate an object’s to look at another object slowly. Like the lookAt function just turns the object at once. But I want to do something that will slowly rotate the object frame by frame. Thanks.

You can use the static version of Quaternion.slerp for this. The following demo illustrates the usage. A Quaternion can be derived from Euler angles via Quaternion.setFromEuler() and from a rotation matrix via Quaternion.setFromRotationMatrix().


@Mugen87 thanks this helped alot. But this example has a predefined angle. The problem that I am facing is that how do I find the angle between where the first object is currently looking at and where the second object currently is. I know I can use the angleTo function of Vector3 to find the angle. But I can’t find the forward vector of the first object.

All objects (except cameras) look along the positive z-axis per default. You can now do this:

var vector = new THREE.Vector3( 0, 0, 1 );
vector.applyQuaternion( worldQuaternion );

worldQuaternion represents the orientation of the object in world space.