Detect initial collision

Yet another newbie question! Does anyone know how I can detect just an initial collision. I don’t suppose there some kind of onCollisionEnter or Exit events?

1 Like

I was able to sort this by setting some booleans in the collision event but if there is an easier way I’m all ears.

Hi Rory, welcome to the new BJS forum… sorry for the slow replies.

Is there any chance you could build a playground demo for this? We don’t have many details.

Are you doing camera-to-mesh collision? Or mesh-to-mesh, using scary moveWithCollisions()? Using scene.collisionsEnabled? Or doing rudimentary intersectsMesh testing? Or using actionManagers? Or onCollideObservable?

There are SO MANY things we don’t know. :slight_smile: Try to make a playground for us to do tests-upon, or at least tell us lots more. (thx!) I think you would like anyMesh.onCollideObservable… it rocks, and is easy to use.

ActionManager onIntersectionEnterTrigger is nice, too… but it wants to know WHAT “other mesh” you want THIS MESH… to check-for collisions-with.

Scroll down just a bit, and you will see some demo code… using onIntersectionEnterTrigger.

Notice that it ALWAYS needs an “other mesh” parameter/value. Not all of the other collision-testing methods listed above… require an “other mesh”.

It would be nice if actionManager onIntersectionEnterTrigger… allowed “any” or * or ? … for other mesh, eh? Maybe soon. :slight_smile: But, adding that feature (and using it) might SERIOUSLY hurt scene performance in many-mesh scenes.

Perhaps we would need to add mesh.isCollidable, brother of mesh.isPickable. :slight_smile: We already have a mesh.checkCollisions = true, but… I think that is for a DIFFERENT system than actionManagers and onCollideObservable. Not sure about that stuff.

It’s a bit complicated. scene.enableCollisions, mesh.checkCollisions, camera.applyGravity, mesh.ellipsoid, camera.ellipsoid, and mesh.moveWithCollisions()… are all part of a SPECIAL collision system designed mainly for FPS games (first-person shooter)… and therefore… designed mainly for camera-to-mesh collisions. This means that mesh.moveWithCollisions() is a bit bad/wrong, as it is being used for mesh-to-mesh collisions. It’s a long story. :slight_smile:

One last thing. Cameras can have invisible mesh parented to them (and vice-versa). This allows some more mesh-to-mesh collision-testing options… that might not normally be available on cameras (which are not mesh).

I hope I didn’t say WRONG things. I do that sometimes. :slight_smile:

1 Like

I assume you’re using bounding boxes or other mesh types as your colliders?


Thanks everyone for the input. Here’s a simple playground. As you can see, I am trying to isolate the initial contact only.

I’ll have a read over your suggestions @Wingnut.

Hello @Rory,

I now understand your issue better. If you initially buffer the collidedMesh.position.subtract(camera.position).length() on collision, then you can measure your collidedMesh distance from the camera against all other collisions on that object. Then if the camera distance is less than or equal to the initial buffered camera distance, that will do it.

I hope this makes sense to you, otherwise perhaps I or someone else can modify your Playground scene.



Thank @Galen, I’ll try that out. If I have any issues I’ll post back.

你好,打扰一下,我想请教一个问题,我有个按键事件,当我点击某一个模型的时候,就会打印出当前模型的边界框信息,然后我有一整栋楼,我需要实现的一个功能就是,当我选中某个模型的时候,他就会把当前模型的上面的模型(假设我选中的是2楼,楼上就是三楼和四楼)隐藏起来,这可能是需要计算碰撞的位置或者其它?我也不清楚,在这期间,我的onCollideObservable 这个关于网格碰撞的事件没有反应,所以,我想说我这个功能我应该怎么做呢