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?
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. 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. 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. 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.
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.
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.
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.