Move look at object to normal (direction of camera) + some distance infront of it, set in render loop for camera to lookat the lookat object (flag lookAtEnabled:Boolean) then tween the lookat object to where its supposed to go, then after about 0.5 seconds start the tween on the camera.
Hey @Darcey, I could see the using the Animation object to do the movements that you’re looking for but one approach that I use, especially with a dynamically changing endpoint, would be to use the Lerp function with the render loop and incrementally move things.
var nextCameraLook = camera.target
var enableAnim = false;
...
// On click, take the picked point or some Vector3, update nextCameraLook, and set enableAnim to true
...
scene.onBeforeRenderObservable.add(() => {
if (enableAnim) {
let deltaX = Math.abs(nextCameraLook.x - camera.target.x);
let deltaY = Math.abs(nextCameraLook.y - camera.target.y);
let deltaZ = Math.abs(nextCameraLook.z - camera.target.z);
// 0.01 is acting as a "close enough" threshold to account for float precision issues
if (deltaX > 0.01 || deltaY > 0.01 || deltaZ > 0.01) {
camera.setTarget(BABYLON.Vector3.Lerp(camera.target, nextCameraLook, 0.05));
// You could also probably use lookAt instead
}
// If we're close enough, finalize movement and disable animation
else if (camera.target !== nextCameraLook) {
camera.target = nextCameraLook;
enableAnim = false;
}
}
});