Constrain camera vertical height

I’d like to prevent a camera from going under my heightmap. The heightmap doc page has a good example in Babylon.js Playground, but you can still pan under the heightmap with control + click.

In https://www.babylonjs-playground.com/#95PXRY#86 I tried adding something based on camera._position.y being lower than a certain value, and although I can see this is being triggered, the subsequent camera.y = 120 isn’t. I’ve also tried it with setPosition.

This cannot work:
image

camera.y is not a property :slight_smile:

You have to use setPosition: https://www.babylonjs-playground.com/#95PXRY#87

Thanks! Any idea how to stop the jitter on https://www.babylonjs-playground.com/#95PXRY#88 (have changed 120 -> 20) if I try to move the angle quickly?

You can try to reduce the remaining inertia maybe:
https://www.babylonjs-playground.com/#95PXRY#89

1 Like

Great, thanks.