ArcRotateCamera Target position limit

Hi

I got a scene in which I want the user to orbit around a shape. I can have a box around that shape and will like to have an ArcRotateCamera Target always be inside of it. Like a boundary for panning but not to the camera, but to the target of the camera.

And this box might be rotated.

How to do it?

“panningDistanceLimit” is not doing the trick here.

I created a startup PB. The sphere is just to visualize the camera target. The box is the limiting area.

https://playground.babylonjs.com/#VVP3MM

Regards
Peter

Pinging @PolygonalSun

Hey @peterimg, so if I’m understanding this correctly, you want to have a shape that you can move around, within the dimensions of a box. In addition, you want to make it so that the camera’s target is always set to that shape also, have the ability to rotate around things, is that correct?

I want to pan the camera and I want the camera target to be in a box. And stop panning if it’s out of it.

The sphere is just to show where the target is.

And on top of that, have all other ArcRotationCamera features but i need to limit target movement to a box while panning.

So off of the top of my head, I don’t think that panningDistanceLimit would work for limiting with respect to the space of a cube as it just prevents the camera from panning outside of the given limit (think of it like a sphere shaped limit). You might have to custom make an input that checks if your camera’s axes are some value from a given point and stops movement: Customizing Camera Inputs | Babylon.js Documentation (eg. x, y, or z can only be +/- 5 from 0)

I try to understand this but it’s not coming to me how to achieve this.

Can you make some simple PG with example?

Regards
Peter

Hey, I apologize for the long delay in response but I just wanted to touch base about this topic. Creating a custom input can be a bit complex because you’re effectively overwriting part of the input code with a custom solution. I’ve written an blog post that that will hopefully help clear some stuff up: Medium

Furthermore, here’s a TS PG that shows a re-implemented version of the ArcRotateCamera. All input for the ArcRotateCamera is run through the onTouch function so if you were sort of create a version of onTouch that could have code to check where your camera’s target is and restrict accordingly.

1 Like