Search Unity

Dynamic Animation Start

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

  1. AlbinoRacoon

    AlbinoRacoon

    Joined:
    May 3, 2020
    Posts:
    3
    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;
    2.  
    3.     void Start()
    4.     {
    5.         Blinds = GetComponent<Animator>();
    6.     }
    7.  
    8.     void Update()
    9.     {
    10.         if (Input.GetKey(KeyCode.Space))
    11.         {
    12.             Blinds.Play("Roll");
    13.         }
    14.  
    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).