Dad72 Posted February 3, 2017 Share Posted February 3, 2017 Hi, 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; actor.excludeCollisions(Player); actor.excludeCollisions(NPC); But excludeCollisions does not exist, or something similar. Is this possible, how can this be done? Thank you Spankied 1 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 3, 2017 Share Posted February 3, 2017 @Dad72 Can't you just set otherPlayer.checkCollisions = false; NPC.checkCollisions = false; Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2017 Author Share Posted February 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 3, 2017 Share Posted February 3, 2017 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 return; } //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 Quote Link to comment Share on other sites More sharing options...
Raggar Posted February 3, 2017 Share Posted February 3, 2017 What about collisionFilterGroup and collisionFilterMask? These are Cannon.js variables, and should be able to achieve what you want. At least natively. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2017 Author Share Posted February 3, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2017 Author Share Posted February 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
reddozen Posted February 3, 2017 Share Posted February 3, 2017 As long as they aren't standing next to a wall close enough to clip out as they're leaving the characters personal space. aWeirdo 1 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 3, 2017 Share Posted February 3, 2017 @Dad72 The possible downside of that; what if actor or NPC is colliding with a wall or something at the same time? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2017 Author Share Posted February 3, 2017 Indeed, this may not go. I can not find an idea. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2017 Author Share Posted February 3, 2017 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 ? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 3, 2017 Author Share Posted February 3, 2017 In fact this solution I do not like also. I drop this idea, the characters will collide with each other. If I disable the collisions of the characters at a time, it will fall off the ground, so this is a bad idea. Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 4, 2017 Share Posted February 4, 2017 @Dad72 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; into box2.collisionFilter = 1; you'll also start colliding with the high box. If a mesh.collisionFilter is not set, it will default to 1. http://www.babylonjs-playground.com/#20PQBI#1 sadly this ofc requires source code edits, but i hope it meets your needs Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 4, 2017 Author Share Posted February 4, 2017 This is excellent. Go to the PR of this function. I can do it if you want. Thanks aWeirdo. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 4, 2017 Author Share Posted February 4, 2017 PR done ! Have all my thanks aWeirdo Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 4, 2017 Share Posted February 4, 2017 @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. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 4, 2017 Author Share Posted February 4, 2017 AH, I cancel the PR. Would you do the PR with your patches? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 4, 2017 Author Share Posted February 4, 2017 It works for me. Here the camera has a filter of 3, a box with a filter of 2 and the other box with a filter of 1. and it works. http://www.babylonjs-playground.com/#20PQBI#3 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 4, 2017 Share Posted February 4, 2017 @Dad72 box2 is the high box, and i'm running strait through it Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 4, 2017 Share Posted February 4, 2017 fixed it here; http://www.babylonjs-playground.com/#20PQBI#8 I'll start working on a PR, might take a little while, need to update all the cameras. Decided to only add support for freeCamera at this moment, i'm not sure which other camera's would actually be used with this. Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 4, 2017 Author Share Posted February 4, 2017 Ok, in fact you want the camera with a filter of 3 to collide with the lower filter objects (1 and 2 but not 3) Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 4, 2017 Share Posted February 4, 2017 exactly, so moving cameras & meshes only collide with meshes that have a lower filter, only exception being if both filters are 1, it will act as it does today. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.