Forum rules - please read before posting.

Can the start of a new loop in an animation be delayed?

I think this isn't really AC-specific, but I was wondering if there is a way to delay the start of the next iteration of a looped animation by a specified number of seconds? I have an idle animation for a character that I want to play repeatedly, so I have the Loop Time? checkbox checked, but there doesn't appear to be a way to set a delay. It does not seem like the Cycle Offset field was not intended to set a delay. In the animation controller, there is a Speed setting for the animation I can fiddle with and also another Cycle Offset field, but no delay start field I can see.

Is there a way to do this, or do I need to make this a custom animation instead of the idle animation, and then just trigger it via ActionList?

Comments

  • To help understand the context: is the intent for this to provide variance to the idle animation, e.g. a "waiting" animation that plays if the idle animation has looped for a while?

    The Animator doesn't have a means to do this by itself - but you can set up a transition from your regular Idle animation that goes to the next animation once a given parameter (e.g. a Trigger named "NextIdle") has been invoked.

    You'd then just need a custom script, attached to your character, that invokes this Trigger parameter once they've been in the idle state for the given number of seconds.

    Here's one, named IdleChanger.cs:

    using UnityEngine;
    using AC;
    
    public class IdleChanger : MonoBehaviour
    {
    
        public float changeTime = 5f;
        public string triggerName = "NextIdle";
        private Char character;
        private float timer;
    
        void Awake ()
        {
            character = GetComponent<Char> ();
        }
    
        void Update ()
        {
            if (character.charState == CharState.Idle)
            {
                if (timer < changeTime)
                {
                    timer += Time.deltaTime;
                    if (timer >= changeTime)
                    {
                        character.GetAnimator ().SetTrigger (triggerName);
                    }
                }
            }
            else
            {
                timer = 0f;
            }
        }
    
    }
    
  • Oh wow, thank your posting that snippet! So the intent is to not play another a different animation, just to have a pause in the loop. Do idle animation, pause X seconds, repeat.

  • With the way Unity's Animator system works, you can't associate a "delay" with an animation state - instead, you'll have to play a different animation as above, but have that animation just be a loop of the regular Idle animation's first frame, lasting for as long as you want the delay to last.

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.