Animating camera target also changes position

I’m not 100% sure this is a bug but it is pretty surprising behaviour: How to animate changing camera target - #2 by ajp

That’s because you’re using an ArcRotateCamera :slight_smile: when the target of an ArcRotateCamera changes, it will also update its position so that its distance radius to the target stays the same. For finer control over the camera’s target and position, you’ll want to use the Free/UniversalCamera Animate changing camera target | Babylon.js Playground (babylonjs.com)

3 Likes

Great thanks. I think the confusing thing for me was that changing the target with camera.target = new_target did not result in the position changing. But when animating its target the position did change. Is that the intended behaviour?

I checked with @PolygonalSun and yeah, that’s intented behavior. What happens is, if you update the target vector without changing its reference (which is what the animation does under the hood), it will keep its existing radius, alpha and beta parameters, which results in the position having to change to accommodate that. But if you use camera.target = … or camera.setTarget(…), then it will recalculate the radius, alpha and beta so that the position doesn’t change. setTarget has a parameter to stop this recalculation, so that it behaves like the animation, but that parameter is false by default. I updated the playground with these different forms of updating the camera target: Animate changing camera target | Babylon.js Playground (babylonjs.com)

3 Likes

Good to know. Thanks. Yes I can get it to update the position using camera.setTarget(pos, true, true, true)

I believe this should be written in the breaking changes of version 5.

If you take this playground : https://playground.babylonjs.com/#IA5B1R#6 (same as version 1 but without the position animation), and you change the Babylon.js version to 4.2.1, the behavior is not the same as on version 5.19.0.

@carolhmj :point_up: fchoisy makes a good point, this looks like a breaking change.

Yep yep I was discussing with the team, @RaananW can we add this manually to the breaking change list somehow?

1 Like

sure, it requires a small edit. assign it to me, i’ll do it and document how to do it for future reference

1 Like
2 Likes