How we can achieve advance collision detection with arcRotate camera

Could someone please assist me with this situation?
How can we manage this issue and change the camera radius dynamically based on the collision event? (without use the checkCollisions method)?

cc @PolygonalSun

That’s a very interesting question. I’m eager to read the answer.

Conceptually, there needs to be a way to determine when the player is obstructed. The first thought that comes to my mind is to try using ray picking. The working assumption here is that if there are one or more meshes in between the camera and the player, we want the camera to then be in front of all of those meshes.

What you could try is to fire a ray from the player or camera target (origin) to the camera (target) and check what the first mesh is that gets hit. The picking info provided by that pick should then give you a point where the ray actually hit. You could then use that point, with player’s position (or the camera’s target), to determine what the new radius should be.

1 Like

Yes, my concept was to create a ray between the player and the camera, like you mentioned. But, could you kindly explain to me how we may compute a new radius based on the new obstrat position?
And again reset it?

Actually, it is already implemented here in a simple way - GitHub - ssatguru/BabylonJS-CharacterController: A CharacterController for BabylonJS

1 Like

I would recommend a very cheap way.

  1. create cameraHitBox(mesh.createBox)
  2. and set cameraHitBox camera under (CameraHitBox.parent = camera)
  3. and try to any some this
    CameraHitBox.isVisible = false;
    CameraHitBox.isPickable = false;

let tempIsHi = false;
scene.onAfterRenderObservable.add(() => {
if (CameraHitBox.intersectsMesh(hitObject : tree in video)) {
if (!tempIsHi) {
tempIsHi = true;
//start event. example : camera.radius = 3;
} else {
tempIsHi = false;

1 Like

Oh, That’s nice but does it handle the camera with collisions only from this ‘elasticity’ (bolean)? Or are there any options to further tweek the camera behavior/transition on collision?
And then, sadly I should say, the demo doesn’t show this.
I only found this short part in the description
“By default the camera behaves “elastically”. In other words if something comes between the camera and avatar the camera snaps to a position in front of that something. This way the avatar/player is always in view. To turn this off use…”

Well, worth trying it out anyways.

Yet I believe the idea of eventually having this behavior (with options) as an integrated part of the camera behavior for 3rd person cam in BJS would probably be an awesome piece to have, wouldn’t it? @PolygonalSun

1 Like

@11128 Thank you for your assistance. The experience is not smooth since the screen flashes when adjusting the radius, and the radius is static, which will not function in a dynamic collision situation.

You may try it here -
(It uses CharacterController with some modifications for better elasticity).


Nice, thanks. Didn’t realize you implemented this in your project. Thanks for the tip and have a great day :sunglasses:

1 Like

@labris It’s fantastic, however we’re not utilising the navigation plugin. Would anyone be willing to offer their playground as a demonstration?

@Nilesh_Ghanchi We also don’t use navigation plugin, just this CC - GitHub - ssatguru/BabylonJS-CharacterController: A CharacterController for BabylonJS

1 Like

Thanks @labris. It works for me thank you so much


I want to thank all of you for a great support. :smiley:


@labris It would be great if you could help me with a little issue with how you handled the camera’s reset radius once it was free of collisions in your project.

Hi Labris, I have my babylonjs set-up as one html file. How do I integrate this controller into my html file? Do I need to change the set-up of the file into multiple files? -
I’m just creating a third person view so I can walk around the city in third person.

Hi James,
Hope you are well. Don’t know the answer and hopefully @labris will answer soon.
Just wanted to ask ‘Please let me know when it’s ready’. I’d love to have a look at how your scene looks from a street view. Meanwhile, have a great Xmas :christmas_tree: :sunglasses:

Hi Mawa, I’m good thank you. Hope you are too :slight_smile: and hope you are having a great xmas holiday.
Thanks, It’s still a bit buggy and slow but hopefully it will be good enough when it’s all set to walk around and probably optimized a bit more.

1 Like