Restrict camera from moving below scene

Is there a way to restrict the camera from moving below a scene? I want to be able to rotate around it just not below it.

Not sure if I get you, but are you finding ArcRotateCamera | Babylon.js Documentation?

What does your scene contain? I’m using the following code to keep the gamera above a ground object:

    const ray = new Ray(this.camera.position, Vector3.Down(), 1).intersectsMesh(this.ground)

    if (ray.hit) {
      this.camera.setPosition(new Vector3(this.camera.position.x, ray.pickedPoint!.y + 1, this.camera.position.z))
    }
3 Likes

The answer is ‘Yes’ and the solution(s), that are nearly always multiple in BJS, depend on the type of camera. What camera are you using?

Yeah, I posted this when I got a little frustrated with the docs. I understand this camera decently now

love this, I have been learning more about ray tracing recently. This is very helpful

turning on collision for the camera will cause it to not go through the ground.

2 Likes