How to prevent camera to pass target?

Wassup Folks!

I am migrating a fairly large three.js codebase to Babylon and I’m struggling with pretty much every aspect at the moment, so forgive my ignorance if it’s obvious or if the question has been asked previously, I couldn’t find a related topic out there…

I have a basic scene setup using an ArcRotateCamera, if user zooms too close from the target, then the camera will go beyond the target and start acting reversed, like if I was on the other side of a mirror. I do not want that, I would prefer the camera to stop zooming in when getting too close from the target, so user can still interact normally and eventually zoom out.

Is there a built-in setting to enforce that behavior? or if not what’s the recommended way to implement that?

Thanks for your insights

Welcome!

if (camera.radius > 50) {
camera.radius = 50;
}
if (camera.radius < 0.30) {
camera.radius = 0.30;
}

1 Like

Or

camera.upperRadiusLimit = 50;
camera.lowerRadiusLimit = 0.30;
2 Likes

I didn’t know that one yet, its probable the better solution.

1 Like