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)

2 Likes

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