Collision misteries

Hi there:

In this PG, you can see that the dark blue box can be dragged and forced to collide in a (more or less *) correct way with both the light one and the room’s walls.

However, when dragging the light blue box, it is kept away from the other box, and also the walls, as having a perfectly cubic BB, even not being so, according to the one shown in red.

What is happening here? How can I modify the correct light box BB and show it, in order to solve the issue?

(*) Note that both cubes overlap at the corners, as if it was using a sphere/ellipsoid technique instead the AABB one.

cc @Cedric

1 Like

Hi there @Deltakosh and @Cedric:

I just realize that tweaking the ellipsoid for the light blue box (dummy2.ellipsoid = new BABYLON.Vector3(0.25, 1, 0.25);) does the trick, as you can see here.

Anyway, I’m not sure how is that working, and I find the BB shown by dummy2.showBoundingBox = true; a bit misleading. So I’m now back to the docs.

Best regards.

1 Like

Hi there, @Cedric :

I’ve just made here some enhancements to my previous PG, in order to show the ellipsoids (and implementing snapping to the grid).

My hope was that, being able to see the ellipsoids’ extent, It could be much easier to understand the needed values, but I’ve just ended needing to tweak them in an iterative way until reach the more or less correct value.

Can’t catch the reason for bounding boxes, being all the collision thing controlled by the ellipsoids. So at this point I can’t see a clear relation between BBs, ellipsoids and collisions.

Any clues on it?

It will be possible to tweak that up to a certain point. not sure you’ll get exactly what you want.

I did a very quick try with physics in case you want to test it : https://playground.babylonjs.com/#1T170B#2

Another possibility if you are only dealing with AABB is to use a sweep AABB algorithm: https://www.amanotes.com/post/using-swept-aabb-to-detect-and-process-collision

1 Like

Another possibility that looks overkill but might work is to use the character controller : https://playground.babylonjs.com/#WO0H1U#127

1 Like

Hi, @Cedric:

First, let me thank you for your time and advice.

Of course, I’m still a bit reluctant to go the Physics Engine way. All this is, definitively, something that I thought could be done easily with the basic collision functionality (is just a grid with bounding boxes) but finally is costing me a lot.

I have another thread on the forum that initially was opened for a different issue, but ultimately has come to this very same subjects. Maybe you can be so kind to take a look at it, and review my last shared PG there.

Best regards.

Your last PG works great!

1 Like

Hi, @Cedric:

Well, @xiehangyun provided some serious “corners overlap-avoiding” code there, but note that:

  1. the (shy) little box refuses to contact the walls (this can be solved reducing its ellipsoid, but such a solution is definitively awkward and counterintuitive);
  2. the imported GLB models don’t collide at all with nothing except the walls (?);
  3. the dummies (boxes) doesn’t collide with the imported models.

Any thoughts on it?

I guess it’s due to negative scaling. Did you try to bake geometry? Also, adding an invisible parented box to the glb meshes might improve things. If it’s AABB only, try using the swept AABB algorithm as it’s very stable.

I made some changes to your example.

1 Like

Thanks a lot @xiehangyun:

Great! It seems to work as expected! I’m going to inspect the code in detail and let you know.

But again, thank you very much for your invaluable help!

Hi, @xiehangyun:

After reviewing your code I find it very interesting the way you’ve implemented the fine tuning collision in terms of testing progressive increment desplacements between the moving one and the rest of collision meshes.

Nevertheless I’ll code some clamping for the maximum movement per frame, in order to prevent tunneling through meshes in the case of fast mouse motions.

Thank you very much for your advice and help on this.

1 Like