[SOLVED] Coroutines in Playcanvas

I’m used to working in Unity where i can use coroutines to animate an entity over time or animate pretty much anything (like a score counting up or a health bar counting down to a specific value), all through code.
Now, i’m not very familiar with JavaScript but I wonder if there is a way to have the same kind of behaviour in JavaScript? or maybe there is a different way to animate values or entities in PlayCanvas that I don’t know about, then please share them because that is exactly what i’m looking for but can’t find it.

Thanks in advance!

There’s nothing built into PlayCanvas that does coroutines. There may be some opensource libraries that will allow you to do that though.

Otherwise, you will have to do it in the Update function over time.

Hi,

Thanks for your fast reply!

But isn’t there any solution to this in JavaScript? i read somewhere that there is something called “RequestAnimationFrame” but i’m not really sure how it exactly works.
How else can you animate a score or entity over time? in the update function is an option but i would think it’s kinda hard to do it there and to have full control on how fast the animation and other settings are…

Hi, i found a solution to this problem. Not specifically coroutines, but the animation part.
After searching for a whole day, i found that on the github page of playcanvas, there is a script that can “tween” values over time. i didn’t know this was already implemented in the engine but apparently it is.

you can find it here: https://github.com/playcanvas/playcanvas-tween