Camera collision with walls cannon.js

I want an arc rotate camera collide with walls that use physical impostor cannon.js how can I do it?

:B

I also wonder what engine physics should use cannon, oimo or ammo .__.

pinging @trevordev (wondering if we could add an example for this use case in our examples)

What is the camera used for? Are you trying to make a fps character camera or are you trying to orbit an object but avoid the camera going through walls? Would gravity be applied to the camera?

second option trying to orbit an object as for a game in third person

camera without gravity

(sorry for the ugliness of the example but I’m trying what I need before doing something better ) xD

My recommendation here would not be to use physics because it sounds like a raycast might be better as you want the camera to be positioned from the characters position in a direction until it reaches a distance or hits a wall. (Here is an example of what I described http://niftykick.com:4000/, let me know if this is not what you want)

To do this you can use the freeCamera and use pointer observable events (similar to done here https://www.babylonjs-playground.com/#BEFOO#365) but instead of moving the object move rotational position of the camera. Then every frame cast a ray using scene.pickWithRay (as done here https://playground.babylonjs.com/#NU4F6Y#0) to cast a ray from the position of the character to where the camera should be, if it hits a wall position the camera there.

oh thanks … that’s what I need, I did not know about raycast: S

I will try to implement … will not you have some example code?
like the one in your example http://niftykick.com:4000/?

We don’t have a full example for this but you can look at the source code for arcRotateCamera to see what it does. Here’s a playground to get you started that allows you to circle around as you move the mouse: https://www.babylonjs-playground.com/#BEFOO#372

1 Like

Hello, consulting a problem, is very physical collision memory, I didn’t use any physics engine field, just for the camera and the grid opens the collision, after loading scenarios, I look at any local FPS is only 20 the following, when my camera to collision and grid, reduced to 8 FPS will direct the following, if I open the collision, the frame rate is no problem, and very smooth, I would like to know what reason is this

@ranwei-001 Can you repro this in a playground so we can see what you are seeing and debug?