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 - https://portal.metadojo.io/
(It uses CharacterController with some modifications for better elasticity).

3 Likes

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

2 Likes

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

2 Likes

@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? - https://theblockcity.com/metaverse.html
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