Hi! I have an Anim Component with 3 layers. I want to change the layer through code. How can I do it?
One for @Elliott
what do you mean by “change the layer”? What specifically are you trying to do?
I’m using layers as a way to organise my animations. For example, I have Idle and Run states, but the player can be in normal form, zombie form or ghost form. I have Idle and Run animations for Normal form in one layer, the ones for Zombie form in another layer, and same with Ghost form.
Its a simplification, because I have lots of other states, so I plan to change from one layer to another, for example, when I’m running, I get bitted, and I change to Zombie form, with Zombie run animation.
Is understandable? I’m using layers in the correct way? If not, how you recommend me to do what ? Im searching.
PD: I’m avoiding have tones of states like ZombieIdle, ZombieRun, etc. That’s why I was trying to use layers.
What’s the difference between idle -> run between the Zombie/Ghost/Normal?
I understand that the animations would be different but is there any difference between the state logic in terms of timings etc?
It will be different just in the way it’s displayed. Zombie animation will be more slowly with hands up, but will be activated, just as the Normal one, when the player moves. Same with Ghost, more spooky animation with changes in the transparency of the model, but activated on player move.
I’d say blend trees are currently the best way to achieve an effect like this. However, they aren’t currently available yet in the editor UI so it’d require setting up your anim component via code. You can see how you can set up blend trees here: https://playcanvas.com/editor/scene/989250.
Essentially you’d set up each state such as Run as a 2D blend tree containing containing NormalRun, ZombieRun & GhostRun as it’s children, these can then be switched between by updating the two parameters that control the 2D blend tree.
Here’s the PR that originally introduced blend trees to the engine: https://github.com/playcanvas/engine/pull/2443. It gives an overview of how they can be used.
Would not this be just a 1D blend tree and a single parameter to control it? Is it’s basically a selector to pick one out of 3 animations. @Elliott
A 1D blend tree will be fine to switch instantly to either of the three animations or blend between two animations. If it’s necessary to blend smoothly between any of the three animations, you’d want to use a 2D cartesian blend tree.