Multiple triggers for the same action?

Example: Click a door to open it. But I also want it to open when clicking the doorknob. The door and the doorknob are separate meshes. The door will close when either is clicked also.

How do I do this without repeating code and checking if triggers are already triggered? There has to be a simple way that eludes me!

Hi,

Try to make the doorknob isPicakble property wrong. I think it’il work :")

A second method. Take the door and doorknob into a group at the design stage. Then click on this group. In this way, both will have the same feature. And it will do the same.

Not sure what you mean about making isPickable wrong. Wanna explain a little more?

Yes, the second method might work, but I have different materials for both meshes, I was under the impression that to group meshes, the materials should be the same?

Combining the meshes wouldn’t always be a solution though. For example: 2 light switches, both quite a distance from each other, switching on/off the same light. To put those switches into one mesh would be nasty. There has to be a more elegant solution… I hope :sweat_smile:

just seperate the execute function, use the same function for both meshes, and store/read information from single mesh. e.g. even if knob mesh is clicked, check door mesh if it’s open or closed.
https://playground.babylonjs.com/#WC7BU5

1 Like

That’s what I’m currently doing. I just hoped there was a simpler way that didn’t require checking if open/closed, and didn’t require registering the same action for each trigger.

You can make knob isPickable false, maybe?
https://playground.babylonjs.com/#WC7BU5#1
in this case the ray from click goes throw it, so each time is called same actionManager from the door

@PatienceAllergy
This is how you do it.
Any other way only complicates it.

e.g, to avoid the “if open or closed” check, you’d have to make 2 different triggers and swap between them, so on click 1 = call openDoor function, switch trigger to closeDoor function, on click 2 = call closeDoor function, switch trigger back to openDoor function, etc etc.

@MarianG
But it’s the exact same actionManager/Trigger being used by the door.
So whether it picks the door or the knob makes no difference :confused:

Ahhh, I see what you mean now. That is an excellent idea! Thanks! :smiley:

1 Like

I know, and basically I think it has no effect (performance), but in this way, as example, you can assing other actionManager to knob.

I made a simple example of what I’m trying to do here:

https://www.babylonjs-playground.com/#6IH516

BUT I couldn’t figure out how to use a shared function to cut down on code like @aWeirdo suggested. Can anyone show me how to make this example better/simpler?

Here, using 2 actionManagers, but same actions
https://www.babylonjs-playground.com/#6IH516#1

2 Likes

Wow. I would never have come up with that. Thank you so much!

We should have multiple triggers to avoid a lot of loops

const options = {
	trigger: [ActionManager.OnKeyUpTrigger, ActionManager.OnKeyDownTrigger],
	parameter: ["w", "a", "s", "d"]
};

scene.actionManager.registerAction(new ExecuteCodeAction(options, callback));