I’m using the lookAt() function to rotate a 3D character towards a vector. However this is instant and doesn’t look natural. Is it possible to animate the lookAt() or have slower rotation so that the result is more natural instead of instant?
@vielzutun.ch feels like you’re being aggressive for no reason - he just asked if there’s a built in function that may help him
And there is one indeed Rants aside, you can mix using state with (s-)lerping to create smooth movement / rotation.
let targetQuaternion;
// NOTE Put this function in your animation loop, so that it’s called on each frame:
const onFrame = () => {
if (!targetQuaternion) {
return;
}
character.quaternion.slerp(targetQuaternion, 0.2);
};
const smoothLookAt = (target) => {
const mock = new Three.Object3D();
character.parent.add(mock);
mock.position.copy(character.position);
mock.lookAt(target);
targetQuaternion = mock.quaternion.clone();
mock.parent.remove(mock);
};
I have a camera and various objects located in different positions. Current when I click on an object, I perform the following code to for ce the camera to look at the object:
let wp = new THREE.Vector3();
object[current][active_index].getWorldPosition(wp);
camera.lookAt(wp)
How can I change this to gradually pan the camera to the object over, say, a 1 second period?
From what I know(and I don’t know much), it is easier to use something like Camera Controls to handle all of the rotations, quaternions etc than handling it yourself.
Instead of specifying exact animation duration with Camera Controls, you will need to play with smooth damping settings to fine tune the approx time it takes for animation/transition to reach the end.