Is there any way to auto-play an action?


Is there any way to make a self-playable action? My case is:

  • I have a Coin, and I added an ExecuteCodeAction when the player intersects it. But I want to, after it, interpolate the coin.poisition.y to a higher value, to simulate the effect of “coin fastly bring to up”.

I tried adding the Interpolate on .then, but I noticed on documentation that the actions on .then are fired only when the first action trigger is repeated.

What is the best way to make the “coin.position.y” interpolation starts after the player gets the coin?

I was thinking about a way to make an auto-playable action to call it on the first action callback. Is it possible?

Thanks very much by helping

My current code is:

                    new BABYLON.ExecuteCodeAction(
                            trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger,
                            parameter: playerMesh
                        () => { 
                    new BABYLON.InterpolateValueAction(
                        200 // 200 ms

Well, you can create your action and then call execute on it directly

1 Like

Awesome @Deltakosh , thanks very much for this! It works like a charm

My pleasure and thank you for having flagged it as answered :slight_smile:

1 Like

I’m trying to do this with an Interpolate action that I want to call an execute code action when the animation completes. I can’t seem to get the InterpolateValueAction to call the next action added with a .then. Looking at the code, it looks like onInterpolationDone is called when the animation completes. onInterpolationDone seems to be passed in to the constructor, but by default it is a noop. Seems like it should call _child.execute. Or am I missing something?

Here is a PG that shows what I am talking about: Babylon.js Playground

I am actually trying to chain SetValue action and it doesn’t appear to call it’s _child either

The chain works when the trigger is triggered. Like if you have a click trigger: first action will be on first click and second action (after the then) on the second click. Rinse and repeat

In your example there is no trigger so action 2 will never start

Oh. I thought .then was a way you could chain together actions so you could have multiple actions happen sequentially based on a trigger (or in my case when the action is executed). But it sounds like the intent is that .then describes actions to be taken on subsequent triggering events?

That is correct :slight_smile:

1 Like