Forum rules - please read before posting.

Wait until finish Animator

Hello everyone !

Could someone here guide me? I've searched a lot but I can't find a solution.

I'm using a complex 2D Unity sprite for my character, with point-and-click movement. I've created random idle states (for example, Idle1) triggered by a random integer. If I click to perform a move during the character's Idle1 animation, with ExitTime unchecked everything works fine, the character moves by going to the Walk state but the Idle1 animation is abruptly interrupted. I could be satisfied with that but I'd like to do better.

When I enable ExitTime, the Idle1 animation ends well, but the character "slides" while this animation ends before switching to the Walk animation. In other words, is it possible to wait for the Idle1 animation to finish before the character starts moving? Is there an option like "Wait until finish" to put in a script ( I've tried several but without success) or in a Blendtree? I understand that "Turn before pathfinding" only affects the main Idle.

I guess you would have to remember the click for movement, and it would only execute once the Idle1 animation is finished. Such an option would also interest me for rotation animations (outside idle) before moving.

I hope I'm clear, and that someone could guide me. Thank you very much for your help.

Comments

  • Having the character delay their actual pathfinding call until the animation has finished would be tricky - as it'd involve ignoring the "built-in" call upon clicking in the scene.

    What might be an easier workaround is to be a bit tricky, and instead just set the walk speed to zero if they're playing their "Idle1" animation, i.e.:

    using UnityEngine;
    using AC;
    
    public class FreezeIdleMotion : MonoBehaviour
    {
    
        public AC.Char character;
        private float normalWalkSpeed;
    
        void Awake () { character.walkSpeedScale = normalWalkSpeed; }
    
        void Update ()
        {
            bool freezeMovement = (character.GetAnimator ().GetCurrentAnimatorStateInfo (0).shortNameHash == Animator.StringToHash ("Idle1") && character.GetAnimator ().GetCurrentAnimatorStateInfo (0).normalizedTime <= 0.95f);
            character.walkSpeedScale = freezeMovement ? 0f : normalWalkSpeed;
        }
    
    }
    

    You can incorporate other animations into this if necessary, but try it with just the "Idle1" state for now. If Idle1 is playing, and is less than 95% of the way through, it'll zero the walk-speed - preventing them from moving.

  • Absolutely! Simple and clever! You are opening doors for me, I will be able to better understand the logic and dive deeper into AC.Char and others.

    I reversed void Awake () { character.walkSpeedScale = normalWalkSpeed; } to void Awake () { normalWalkSpeed = character.walkSpeedScale; } for initialization, and it works.

    Thank you very much for the time you've given me.

  • I reversed void Awake () { character.walkSpeedScale = normalWalkSpeed; } to void Awake () { normalWalkSpeed = character.walkSpeedScale; } for initialization, and it works.

    Quite right, sorry about that.

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.