Jump to content

exclude mesh for Collision


Recommended Posts


Is it possible to exclude certain meshes for collisions.

For example, I would like all my characters to check the collision for the objects of the scenes, except with the other characters. In other words, all the characters do not collide with each other, but can do it with the objects of the scenes (wall, trees, rock ...)

I am looking for something like:

actor.checkCollisions= true;

But excludeCollisions does not exist, or something similar.

Is this possible, how can this be done?

Thank you

Link to comment
Share on other sites

If I do this, the characters no longer collide with the objects of the scene. And I want all the characters to collide with the objects, but not between the characters themselves.

So the characters have to detect collisions, except between them.

Link to comment
Share on other sites

i don't know much about the collision system sadly,

but i suppose some kind of "collisionLevel" could be intergrated, so you only check collisions against meshes with lower collision levels . e.g

wall.collisionLevel = 1;
actor.collisionLevel = 2;
NPC.collisionLevel = 2;

// and then adding something like this into the code that checks & calculates collisions.

// if all collisionLevels are default(1) act normal, all meshes collides
// else if this.collisionLevel is not greater than that.collisionLevel, ignore collision between them
if( !(this.collisionLevel === 1 && that.collisionLevel === 1) && !(this.collisionLevel > that.collisionLevel) ){
  //act as if collisions were disabled
//else continue collision check

// examples
// actor vs NPC !(2 > 2) === true (2 is Not greater than 2), ignore collisions
// actor vs wall !(2 > 1) === false (2 is greater than 1), continue collision check.

just an idea :) 

Update; http://www.babylonjs-playground.com/#20PQBI#8

Link to comment
Share on other sites

I do not use the collision of physics. I use mesh.moveWithCollisions and mesh.ellipsoid

A property like mesh.CollisionLevel could work. But Babylon does not have such properties yet. Maybe Deltakosh might have an idea on the subject or add this property

Link to comment
Share on other sites

I think I'll do this with the actions and BABYLON.ActionManager.OnIntersectionEnterTrigger and BABYLON.ActionManager.OnIntersectionExitTrigger

if(OnIntersectionEnterTrigger) actor.checkCollisions = false;

if(OnIntersectionExitTrigger) actor.checkCollisions = true;

Basically if an actor intersects another actor, I checkCollisions = false and when they are no longer, I checkCollisions = true.

I think it can work. to tested. Anyway I do not have too much other possibility it seems.

Link to comment
Share on other sites

Otherwise, I have this solution. As soon as an actor intersects another actor or NPC, I disable the collisions otherwise I activate it, this in a registerBeforRender.

scene.registerBeforeRender(function() {  
    if(actor.intersectsMesh(otherActorOrNPC, false)) {
        actor.checkCollisions = false;
    } else {
        actor.checkCollisions = true;    

But I'm afraid that this is an impact on performance. But I see no other possible alternative currently without something more in Babylon to handle this case.

What do you think of this solution?

I just need to find an idea for intersectsMesh to detect all objects being actors or NPC. Any ideas ?

Link to comment
Share on other sites

I didn't have time yesterday, so here we go..

Assuming you're not using a webworker, Here's an example using mesh.collisionsFilter = number; as described in my idea above.

You'll notise that you collide with the ground and the square box, but not with the high box right infront of you.

If you were to change

 box2.collisionFilter = 2;


box2.collisionFilter = 1;

you'll also start colliding with the high box.

If a mesh.collisionFilter is not set, it will default to 1.


sadly this ofc requires source code edits, but i hope it meets your needs :) 

Link to comment
Share on other sites

@Dad72 There's still a few bugs, mainly related to camera's, it seems they don't pass their own object to the collision code, so their collisionFilter is always reset to 1, meaning that collisions between camera's and meshes are bugging if lets say camera has a filter of 3 and should collide with a mesh with a filter of 2.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...