Collision detection on rotating mesh and what do when one is found?

Hello after a long time, I’m back into using BabylonJS to create something.

So far I have a Position Gizmo and a Rotation Gizmo attached to a cube.

When I detect a collision while changing the position of the cube I do this :
cube.position.x -=; cube.computeWorldMatrix();

Which works for 99% of the cases except when I drag too fast but I will look into later. Though if you have any suggestions please care to mention them.

Anyway what would be the equivalent when I’m changing the rotation of the object via the rotation gizmo attached to it ?

Any guides, sources and general direction would be deeply appreciated. I learnt so much with your help during my first project with BabylonJS and I’m now back for more !

P.S. Correct me if I’m wrong but from my minimal understanding, the computerWorldMatrix() works as a “refresh” so the engine knows again the correct orientation,position,scale of a mesh.

1 Like

Pinging el Maestro @Cedric

1 Like

Hi guys. Here’s a possible testing-playground, currently attempting intersectsMesh (and not doing well, it seems). Other types of colliding likely nearby/possible.

1 Like

Yes, computerWorldMatrix() computes a bunch of intermediate structures and the world matrix. Some kind of refresh of what has a dirty state.

I don’t think I can provide a better sample than @Wingnut 's

For the fast translation, usualy this kind of issue can be fixed by dividing the translation into smaller steps. depending on the vector, compute 1 or more substeps and check the collision. Or, clamp the maximum vector that you can translate the cube with in a frame time.

1 Like

Hi guys.

I made a pretty large mistake in that playground. Fixed… in version #95.

In line 46, I had “precise mode” set to false. Now set to true, and so dragging left-right on the green ring… gives much better intersect activity between the two boxes.

In that same line, we notice that intersectsMesh needs to have a specific mesh collide-target (colliderBox) to check for intersecting-with (for white elongated box).

I don’t know if there is an intersection/collide method… that would trigger/fire… IF white box collided with ANY other mesh (similar to a moveWithCollisions() func, but for rotations instead of translations)

Let’s pretend/imagine that rotation gizmo has an onRotationSphereDragObservable (it does). Inside the handler for THAT… a person COULD “poll” (iterate thru) ALL scene mesh that need checking for rot-collisions (all scene rotation-obstacles/blockers). MAYBE that would be fast enough, depending upon length of obstacles list.

Essentially, a list of scene mesh that are allowed to be rotation blockers. ANYTIME box or rot-gizmo is moving, we constantly iterate thru that list and check for spunBox.intersectsMesh(listedMesh, precise).

Since this “polling” would ONLY happen during user isDraggingRotation = true… maybe performance would remain speedy. Maybe. :slight_smile:

Further rotation-collision tests welcomed by anyone/everyone. Please tell/show results here, as wanted. thx.

Note: Wouldn’t it be nice to have a tubeDiameter setting on these gizmos? Maybe late-settable anytime? (wink) That’s why I up-scaled the rot gizmo… kept missing it with my pointer… gizmo tubes so thin. :slight_smile: (Old-people eyes)

1 Like

I made you go with all this lengthy explanation as I always do with my posts :frowning:

This time after some lengthy thought process I concluded that I will use only the collisions checking when I translate a mesh. The rotation collisions somewhat worked with some interesting results but they are no use of me it turns out.

Really thanks for all the love you put in this. You are a vibrant individual for sure vibing with so much knowledge and excitement.