Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Dynamic Animation Start

Discussion in 'Animation' started by AlbinoRacoon, May 26, 2020.

  1. AlbinoRacoon


    May 3, 2020
    How do I make the start position of an animation be the last position of a previously played animation (even if that animation isn't complete).

    I'm animating blinds rolling up when key is held down and rolling down when key is no longer being held.

    Code (csharp):
    1.   public Animator Blinds;
    3.     void Start()
    4.     {
    5.         Blinds = GetComponent<Animator>();
    6.     }
    8.     void Update()
    9.     {
    10.         if (Input.GetKey(KeyCode.Space))
    11.         {
    12.             Blinds.Play("Roll");
    13.         }
    15.         if (Input.GetKeyUp(KeyCode.Space))
    16.         {
    17.            Blinds.Play("UnRoll");
    18.         }
    19.     }

    The problem comes when the player presses the trigger key and immediately lets go which makes the "RollDown" animation play, and since it's the same animation as "RollUp" just with the speed being set to -1, making it reverse, the start position is the blinds being all the way up, which makes the animation jump.

    So basically what I want is to get the position of the blinds at the moment the key is let go of, and make that the start position of the "RollDown" animation, instead of it being from all the way up (if there's a more elegant solution I welcome those too - the end goal is not to make the blinds glitchy).