# Collisions in Camera and Meshes

**URL:** <https://forum.babylonjs.com/t/collisions-in-camera-and-meshes/15903>\
**Category:** Questions\
**Created:** [November 21, 2020, 12:26pm UTC](https://forum.babylonjs.com/t/collisions-in-camera-and-meshes/15903 "2020-11-21T12:26:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![asheesh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/asheesh/32/12149_2.png) [@asheesh](https://forum.babylonjs.com/u/asheesh)\
**Post date:** [November 21, 2020, 12:26pm UTC](https://forum.babylonjs.com/t/collisions-in-camera-and-meshes/15903/1 "2020-11-21T12:26:19Z")

</div>

Hello!

I am trying to use collision property. The issue I am facing is… let’s say I created a box and have set the property checkCollisions over this box.

```
var box = BABYLON.MeshBuilder.CreateBox('main_box',{height: 30, width: 30,depth:30},scene);
box.position.y=14;
box.visibility=0.8;
box.checkCollisions=true;

```

Inittial position of Universal camera is inside this box. The camera has property like this…

```
var camera = new BABYLON.UniversalCamera(
  "primaryCamera",
  new BABYLON.Vector3(1, 1, 1),
  scene
);
camera.rotation = new BABYLON.Vector3(0, Math.PI, 0);
scene.collisionsEnabled = true;
camera.checkCollisions = true;
camera.applyGravity = true;
camera.ellipsoid = new BABYLON.Vector3(1, 1, 1);
scene.activeCamera = camera1;
camera.attachControl(canvas, true);
camera.speed = 0.3;

```

My goal to use this collision property is to restrict camera movement going out of the box.

The issue I am facing is… camera is moving out of the box… collision property is not able to stop the function… though once camera posiotion is out of the box Its not allowing to enter into the box.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 22, 2020, 3:31pm UTC](https://forum.babylonjs.com/t/collisions-in-camera-and-meshes/15903/2 "2020-11-22T15:31:31Z")

</div>

Pinging @PolygonalSun

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [November 22, 2020, 4:03pm UTC](https://forum.babylonjs.com/t/collisions-in-camera-and-meshes/15903/3 "2020-11-22T16:03:04Z")

</div>



---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [November 23, 2020, 4:58pm UTC](https://forum.babylonjs.com/t/collisions-in-camera-and-meshes/15903/4 "2020-11-23T16:58:24Z")

</div>

Hey @asheesh,

First of all, welcome to the forums! If I’m understanding what you’re doing, you’re using a box mesh to act as a boundary for your camera. Is that correct? If so, then the reason why it’s not working is because you’re using a solid object as your bounding box. The collision system won’t be able to tell when you’re colliding because the object can’t actually collide with an object until it’s outside of it. A good analogy is that you can’t be prevented from entering a building if you’re already inside that building. When the camera exits the box, the collision detection can now check and prevent the camera from entering.

Since you’re going for the opposite behavior, there are a couple of ways to do it. You could programmatically restrict the camera, which is fine for simple boundaries but I’d recommend building a “fence”. You can use planes or boxes on the outside to act as your boundaries. Here’s an example of that: [Camera Bounding Box example | Babylon.js Playground](https://playground.babylonjs.com/#V7LQJD). This is modified form of the collision example found on our [Camera Collisions](https://doc.babylonjs.com/divingDeeper/cameras/camera_collisions) page.

Hopefully, this answers your question but if not, please feel free to reply with any other questions.

---

<div class="post-metadata">

**Author:** ![PolygonalSun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/polygonalsun/32/2704_2.png) [@PolygonalSun](https://forum.babylonjs.com/u/PolygonalSun)\
**Post date:** [January 25, 2021, 5:30pm UTC](https://forum.babylonjs.com/t/collisions-in-camera-and-meshes/15903/5 "2021-01-25T17:30:07Z")

</div>


