Checking collision with multiple unknown colliders

Morning first post!

I have a question about collisions - let’s say I have a room with 4 walls and each wall is it’s own objects with collision detectors. Then I have a movable box that represents a character and I want it to collide with the walls - is there a way to provide mesh.interesctsMesh() with multiple meshes, so I don’t have to check for each wall? I tried Mesh.MergeMeshes() but then the whole room becomes a collider and it’s now possible to move.

// Edit
I tried to upload a screen recording but cannot as a new user :confused:

hi you can make Playground we call it PG
in here https://www.babylonjs-playground.

sorry for that please don’t care about that we love new friend at all

and that is babyonjs collisions sample https://www.babylonjs-playground.com/#U8MEB0#0
and docs Cameras, Mesh Collisions and Gravity - Babylon.js Documentation

I think that example uses physics to check for the collisions? I have a sort of “top-down” scene where you move a box around. It’s working fine using
if (player.intersectsMesh(northWall) {
// do stuff
} else if (player.intersectsMesh(southWall) {
// do the same stuff
}…

I’d instead like to do
if (player.intersectsMesh([…list of meshes] or mergedColliders)) { … }

1 Like

i recommend you wait for more experience user for this ( @Wingnut and @Deltakosh & … )
but i try answer you by my way .
sample under progress …

1 Like

Hello, why not just simply do something like that:

var list = […list of meshes];

for (var colliderIndex = 0; colliderIndex < list.length; colliderIndex++) {
   var collider = list[colliderIndex];
   if (player.intersectsMesh(collider) {
    // do stuff
    break;// exit loop
   } 
}

Hey, thanks for the reply.

Wouldn’t it be computation heavy to iterate through 200 different meshes on each frame? That sounds very heavy.

What about collisionGroups, I read about that yesterday a bit I think - would that work?

Well in any case, the system will iterate throught all active colliders (but it is smart enough to early reject colliders which are too far)

I’m not sure to see what collisionGroups are :smiley:

Yeah I was of the impression that some kind of magic would happen inside the engine to not iterate over it all, or merge it or something :slight_smile :slight_smile:

This bit - New properties; collisionGroup & collisionMask added to babylon collisions. - Announcements - HTML5 Game Devs Forum

Oh yeah…well sure collisionGroup can help as a really fast way to reject meshes :slight_smile:

Welcome to the forum @Foxhoundn from me. If wrapping your character in a sphere is good enough for collisions then here are 200 spheres colliding in a box https://www.babylonjs-playground.com/#HIM0WS#1; or a bit slower Babylon.js Playground

And a number of spheres can be wrapped around more complex shapes Babylon.js Playground

Read about the methods used from here --> Collisions Introduction - Babylon.js Documentation

Happy development

Hey, yeah I have my char wrapped around in a box collider and it’s working great, but I have to check for every single object I add to the game manually (e.g. loop), even objects that are on the other side of the map unless I check the distance, which is kind of a bummer. Something like mesh.isInCollisionWithGroup(“nonWalkThroughMeshes”) would be fantastic :slight_smile:

Thanks for the reply!

1 Like

https://www.babylonjs-playground.com/#UGLGTJ#77

pick on scene for walk
and rotate scene for chose direction

use ray casting for make collision
under progress

https://www.babylonjs-playground.com/#UGLGTJ#92 with 20 other cpu_players
https://www.babylonjs-playground.com/#UGLGTJ#93 single player

left Pointer down = walk | stop
right pointer down = jump

not have walk direction correction when colid in hard slope yet

fun : https://www.babylonjs-playground.com/#UGLGTJ#94 flowers
https://www.babylonjs-playground.com/#UGLGTJ#95

+1 to this topic.
Am trying to build a mindcraft like snapping function… where you can add one object on top of another easily… so am trying to detect collisions on mousemove during a drag event. Using this loop technique, I’ve got a mesh collision check loop happening on every mouse move! Loops in loops.
b