Hello, can I use function for OnIntersectionEnterTrigger? Please your help.


Hello, can I use function for OnIntersectionEnterTrigger? Please your help.


Didn’t try it but I don’t see why it wouldn’t work. Instead of a SetValueAction, try use ‘ExecuteCodeAction’.
As @mawa said, ExecuteCodeAction will work but note that a single action can be registered for the OnIntersectionEnterTrigger / OnIntersectionExitTrigger triggers (as per the doc): if you register several actions for those events, only the first one will be executed.
Here is the example - https://playground.babylonjs.com/#J19GYK#466
It does the same thing with donut scaling, but also changes its material.
donut.actionManager.registerAction(new BABYLON.ExecuteCodeAction(
{ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: sphere },
function () {
donut.scaling = new BABYLON.Vector3(1.2, 1.2, 1.2);
donut.material = greenMat
}
));
donut.actionManager.registerAction(new BABYLON.ExecuteCodeAction(
{ trigger: BABYLON.ActionManager.OnIntersectionExitTrigger, parameter: sphere },
function () {
donut.scaling = new BABYLON.Vector3(1, 1, 1);
donut.material = blueMat
}
));