Search Unity

2D Animation Question

Discussion in '2D' started by DaRaccoon, Sep 9, 2019.

  1. DaRaccoon

    DaRaccoon

    Joined:
    Oct 28, 2018
    Posts:
    4
    Hi,
    I wanted to do a very basic thing with my animator but i can't figure out how to properly do it.
    I have all the animations set and working in the animator, but i wanted to add a little transform manipulation on an axis so that the jump has some initial "push" feeling (I just wanted to squeeze and release the sprite before the jump animation).
    I have my jump transition working with the "Jump" trigger, it loops as long as you don't touch a surface and it's working as intended
    So, how can I add this transform behaviour in the animator without breaking it all? i know i could just add it in the Jump animation, but because it is looping it would loop the squeeze too and it's not what I want to do.
    I tried to use the same trigger and make the animator go Idle ----(JumpTrigger)---> PreJump ----(JumpTrigger)-->Jump but this ends up breaking a lot of things... so what's the proper way of doing it?

    Note: I know how to create the animation, i just want to know how to put it in the animator and transition it to Jump correctly
     
  2. SAVVU

    SAVVU

    Joined:
    Dec 6, 2015
    Posts:
    20
    Hey DaRaccoon,
    You could use a function call inside the jump animation at the first frame and since its looping have a bool variable to ckeck if its time to squeeze(first loop of animation). Set the bool to false inside the function and reset it only after the jump is completly over and you are on the ground. That way you will squeeze once each time you jump.

    For example here is my idea in code:
    Code (CSharp):
    1. public void PreJump(){
    2.    if(squeeze == true)
    3.        this.transform.localScale = /* squeeze transform */
    4.  
    5.    squeeze = false;
    6. }