Universal camera setTarget animation problem

Hi everyone,

I managed to create a playground to demonstrate my problem.
https://playground.babylonjs.com/#MG5H8Z

The spheres are pickable. when you click on one, the camera should have two animations. one that sets the target, and another that sets the position.

But when I click on the mesh, the camera first immediately sets the target and then animates the position. it doesn’t animate both properties together, it animates them consecutively.

I tried it with both

scene.beginDirectAnimation(camera,[animCameraPosition,animCameraTarget], 0,100,false);

and

scene.beginAnimation(camera, 0, 100, false, 1.0, function()

I feel like I’m missing something very simple but cannot find it :slight_smile:

please check you pg sample - it have error.

  1. you need make detachControl for camera, during animation
  2. try make like this (it work for me):
let cLT = new Animation("cLT", "lockedTarget", 60, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CYCLE); let tPos = (camera as TargetCamera).lockedTarget; keyFrames = [ {frame: 0,value: lT.position}, {frame: 180,value: tPos} ]; cLT.setKeys(keyFrames); camera.animations.push(cLT);

// and start animation
scene.beginDirectAnimation( camera, camera.animations,0, 360, false,1,()=>{
console.log(‘all done’);
});

sorry, I fixed the error:
https://playground.babylonjs.com/#MG5H8Z#1

where in your code did you do detachControl? I couldn’t figure it out.

I tried it with detachControl, nothing changed…

https://playground.babylonjs.com/#MG5H8Z#2

https://playground.babylonjs.com/#MG5H8Z#3
works as you need?

No, the same thing is happening here too.

What I need is:

camera set target taking the same time with position change. so when the camera starts to move, the target slowly changes and arrives at the final point at the same time with the camera position.

what happens is:

set target plays first, then the camera position changes.

no. Target animation also playing. Look: https://playground.babylonjs.com/#MG5H8Z#4
i change easing function and speed - target animation play slowly.

Just play with easing settings for every animation

1 Like