Forum rules - please read before posting.

Question re: 2D Custom Animations

edited December 2018 in Technical Q&A

I want to use some 2D characters I purchased from the Asset Store a while back, for a Zelda-esque project I've got in mind

They're quite flexible in that pretty much all the elements can be replaced or re-coloured, but they use their own custom animation scheme - each character effectively consists of a bunch of sprite-based body parts and clothing items all placed in the correct position relative to each other. Each movable direction (U, D, L, R) has its own unique set of sprites, animated separately (i.e. with its own Animator Controller), looking something like this:

I suspect that it would be a lot of work to replace the custom animation scheme with something a bit more in line with one of AC's standard animation methods

Anyway, after a bit of huffing and puffing I've managed to get some working Player and NPC characters, by using AC's "Custom" AnimationEngine, and by enabling the appropriate Animation Controller GameObject element depending on which direction the character is facing (and disabling the ones that aren't required at that time). That works fine for the Idle and Walk animations. I simply override PlayIdle and PlayWalk

But, I want to be able to initiate a whole load of extra animations too, so currently what I'm doing is to check, in PlayIdle and PlayWalk, whether I"ve fired off another animation, and simply not run the Idle or Walk animations during that time, i.e. something like this:

    public override void PlayIdle()
    {
        if (customAnimator.animationPlaying) { return; }

        customAnimator.playCustomAnim("Idle");
    }

I've diligently searched the relevant sections in the manual, and the Scripting Guide, but I couldn't find a more elegant way of doing it, and for the simple test case I've set up, that seems to work ok, but, is there a better way of handling these extra animations (or, indeed, the whole problem itself)?

Comments

  • If the character's internal "charState" enum is set to CharState.Custom, then standard animation methods (PlayIdle, PlayWalk etc) will not be called.

    With the standard animation engines, this value is set via the Character: Animate Action, overrides for which can also be set in a custom animation engine.

    I'm not totally sure of the need to have a custom animation engine in the first place, however. Both Sprites Unity / Sprites Unity Complex engines support characters support sprite hierarchies.

    One approach you could consider: move all your "Female Character: Down", "Up" etc objects to a shared GameObject that's an immediate child of the root, and assign this shared GameObject as your sprite child.

    You can then set up a single Animator on this object that plays e.g. all directional idle animations at the same time. Create another Animator layer that uses a Blend Tree to control which of the four directional sub-hierarchies is enabled at any one time.

    If using Sprites Unity, you'd then have to write a custom script that animates this Blend Tree according to the character's facing direction. If using Sprites Unity Complex, you could simple hook up the Blend Tree to be controlled by the character's "Body facing angle" float parameter.

  • thanks chris. charState was the thing i was searching for but couldn't find

    if i get a spare moment i'll definitely have a look at your suggestion of moving all the animations onto a single controller, as it would certainly be a cleaner approach than the system i'm using at the moment

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.