Forum rules - please read before posting.

Issue playing custom animation using Character: Animate

edited June 2020 in Technical Q&A

Hello!
Using Unity 2019.4.0f1 and AC 1.71.4.

I'm using Unity Sprites 2D, with the Unity 2D Animation Package.
My understanding is that the main animations should play themselves automatically, and should have no transitions between standard animations for this type of setup, as they're played by name.

Made an NPC that I'd like to play custom hand / arm motion animation at different points when in a conversation.
First of all, is it possible to play the same animation twice in one conversation? My thought was that it would be fine.

The animation does play sometimes, though when it does is inconsistent. For example, the animation is plays a first time in the conversation with this Actionlist setup (using Actionlist: Run in parallel)
https://imgur.com/a/UH6z8ma

At another second point in a conversation, it doesn't play a second time with that same setup:
https://imgur.com/a/Ytzs3Uk
This second point is after a Dialogue Choice is selected which comes from a separate conversation Actionlist:
https://imgur.com/a/1zZ1xJy

Here's a screenshot of the Animation Controller for the NPC:
https://imgur.com/a/XU07Zln

Also, some other details:
I made Idle animations for all directions (Left, Right, Down, Up).
The NPC is only meant to face left always, so only one left facing animation for the arm motion was made ("QuintonMoveArm_L").

Also this animation has the "Loop Time" unchecked in the animation's Inspector, and "Wait until finish?" unchecked in the Actionlist under under Character:Animate -- as this was the only way it would animate at all:
https://imgur.com/a/UFaED5e
Meaning it wouldn't animate if "Loop Time" was checked, and "Wait until Finish?" and "Return to Idle after?" were checked.

Any advice on playing custom animations though Character: Animate?
Any help is greatly appreciated!

Comments

  • If the character only ever faces one direction, you've no need to define directional idle animations. Just set the NPC's Facing directions field to None, and you can reduce your Animator Controller to just "QuintonIdle" and "QuintonMoveArm".

    The issue itself may be due to the use of the Unity Animation package. Try switching the Animation engine to Sprites Unity Complex. This is more in-line with the way Unity prefers animation playback to be handled, since you then rely on Animation parameters.

    If you've (currently) no talking/walking animations, clear all of the "Mecanim parameters" text fields (e.g. "Move speed float") that appear after switching animation engine. Then in your Animator Controller, create a new Trigger parameter (named e.g. "MoveArm"), that causes a transition from QuintonIdle to QuintinMoveArm. Create another transition back to idle with an Exit Time of 1 (so that it automatically returns to idle once complete)

    The Character: Animate Action can then be used to trigger this "MoveArm" parameter instead of referncing the animation by name.

  • edited June 2020

    Thank you! That did the trick.

    Thinking I'll switch all the characters made so far to Sprites Unity Complex, as they'll all play at least one custom animation at some point (NPCs and main Player). And Sprites Unity Complex (mecanim) allows more control / fine tuning over animations.

    Found this script for frame-flipping for Sprites Unity Complex characters as well, which I'll need for other characters -- so that's good:
    https://adventure-creator.fandom.com/wiki/Frame-flipping_for_Sprites_Unity_Complex_characters

    Also tested it with some left/right custom animations, which seems to work fine.

    Not 100% sure about the part on the script's page regarding "Up" and "Down" animations:
    "This script works by inverted the X-scale of the Transform whenever the facing-angle falls between 0 and 180 degrees (or 180 and 360, depending on the frameFlipping value). This will cause up and down animations to be flipped as well. To prevent this, modify these values in the code to suit the needs of your own character."

    Wondering if you might be able to provide some more details on that?

    For example, I intend to use BlendTrees.
    I saw in the BlendTree 'Thresholds' of the "Brain2D_SpritesUnityComplex" example character, that there were angles for the different Walk directions:
    https://imgur.com/a/iSQAqIo

    Would the script need to be expanded to account for the other directions (Up, Down, etc.)? Meaning adding extra "Else/If" statements and the angle/number values to account for any extra, added directions?

            else if (frameFlipping == AC_2DFrameFlipping.RightMirrorsLeft)
            {
                if (spriteAngle > 180f && spriteAngle <= 360f)
                {
                    doFlip = true;
                }
            }
    

    Only planning to add additional "Up", and "Down", directions, by the way.

  • The script works by determining reading the character's facing angle (which ranges from 0 to 360). 0 is downward-facing, and increases to 360 when turning clockwise.

    If you imagine this as a clock hand, angles 1 to 179 are on the left face, while angles 2 to 359 are on the right face. Angle 0 and 360 are straight down, 180 is straight up.

    But at an angle like e.g. 10, the hand is on the left face - but the character is actually facing down, so far as what animation is playing. So, you just need to tweak the angle values in the script so that ones closer to 90 and 270 cause a flip. For example:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class SUC_FrameFlip : MonoBehaviour
    {
    
        [SerializeField] private AC.Char character;
        [SerializeField] private Transform transformToFlip;
        [SerializeField] private AC_2DFrameFlipping frameFlipping;
    
        private void Update ()
        {
            if (frameFlipping == AC_2DFrameFlipping.None || character == null || transformToFlip == null)
            {
                return;
            }
    
            bool doFlip = false;
            float spriteAngle = character.GetSpriteAngle ();
    
            if (frameFlipping == AC_2DFrameFlipping.LeftMirrorsRight)
            {
                if (spriteAngle >= 45f && spriteAngle < 135f)
                {
                    doFlip = true;
                }
            }
            else if (frameFlipping == AC_2DFrameFlipping.RightMirrorsLeft)
            {
                if (spriteAngle > 225f && spriteAngle <= 315f)
                {
                    doFlip = true;
                }
            }
    
            if ((doFlip && transformToFlip.localScale.x > 0f) || (!doFlip && transformToFlip.localScale.x < 0f))
            {
                transformToFlip.localScale = new Vector3 (-transformToFlip.localScale.x, transformToFlip.localScale.y, transformToFlip.localScale.z);
            }
        }
    
    }
    
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.