onTriggerEnter onTriggerExit?

Hey Babylonians,

iam trying to implement some triggerzones into my project. For example if the player gets close to a door, the door opens, if the player moves away again, the door closes again…

In other engines i worked with i would simple put a invisible geometry in place and listen to an onTriggerEnter and onTriggerExit event. Is their something like this in Babylon?

Hey!

yes:
https://playground.babylonjs.com/#KQV9SA#0

2 Likes

A simple example using a trigger attached to the camera and a trigger zone around the door. (Just cube meshes)

Open door by clicking and then walk through the trigger zone - door will close behind you

Magic Book

Stay Safe, gryff :slight_smile:

1 Like

Hi guys. If I may add a quick note, there are similar options for “first person shooter”-game intersections (when player is a freeCamera, for example).

I see my good friend @gryff nearby, possibly replying. Hi G-man, good to see you!

And, of course, he shows us EXACTLY what I was speaking-of. Nice, G! ActionManager… on camSensor box, which is parented to camera. IntersectionEnter/Exit triggers, possibly.

There’s multiple intersection testing/trigger methods… in BabylonJS. Smokin’! FUN!

camSensor = new BABYLON.Mesh.CreateBox(“sensor”, 1, myScene);
camSensor.scaling = new BABYLON.Vector3(1, .1, 1);
camSensor.position = new BABYLON.Vector3(0.0, 0.5, 0.0);
camSensor.checkCollisions = true;
camSensor.isPickable = false;
camSensor.parent = myCamera2;
myCamera2.minZ = .05;

var aTrigger = myScene.getMeshByName(“trigger01”);

camSensor.actionManager = new BABYLON.ActionManager(myScene);

let outAction0 = new BABYLON.ExecuteCodeAction(
{
trigger: BABYLON.ActionManager.OnIntersectionExitTrigger, parameter: {mesh: aTrigger}
},
(evt) => {
console.log(“left0”);
console.log(myCamera2.position);
var animation = myScene.beginAnimation(theDoorL, 40, 0, false, 0.5);
var animation = myScene.beginAnimation(theDoorR, 40, 0, false, 0.5);
//aTrigger.setEnabled(false);
camSensor.actionManager.unregisterAction(outAction0);
}
);

camSensor.actionManager.registerAction(outAction0);

And there is the code - camsensor parented to the camera. The trigger zone loaded with .babylon file

Stay Safe All, gryff :slight_smile:

thanks alot for all your replys.
i was wondering how far can i go with intersectsMesh() or an action manager? 50 trigger obejects? 100? 10 000?
is it somehow managed in the background?