Search Unity

Question How to properly adjust animations with movement

Discussion in 'Animation' started by gasguirre, Jul 5, 2020.

  1. gasguirre

    gasguirre

    Joined:
    Aug 7, 2018
    Posts:
    5
    Hello,

    I'm dealing with trying to set animations along with player movement. however I'm not sure about what am I doing and if it's not over complicating the code.
    I wanted to put animations for idle/walking/joggin/running
    and also for rightSideStrafe and leftSideStrafe
    crouch, etc.

    right now this is the code I have for the UpdateAnimator()
    but I don't know if this would be the best way to do it. or even if will accomplish what I need. it is working well for forwards and backwards animations, but I can't make it work for sideStrafe.

    private void UpdateAnimator()
    {
    float speed = m_smoothCurrentSpeed;


    if (m_smoothInputVector.x > 0)
    {
    GetComponentInChildren<Animator>().SetFloat("sideSpeed", speed);
    }
    else
    {
    GetComponentInChildren<Animator>().SetFloat("sideSpeed", -speed);
    }



    if (m_smoothInputVector.y > 0)
    {
    GetComponentInChildren<Animator>().SetFloat("forwardSpeed", speed);
    }
    else
    {
    GetComponentInChildren<Animator>().SetFloat("forwardSpeed", -speed);
    }
    }


    and here some screenshots of the animator.






    sideStrafe:




    and Locomotion:





    the Locomotion one seems to be working well, however I feel that the code is not well written and could be better formatted to adjust to future animations/cases
     
    Last edited: Jul 5, 2020
  2. arvindchetu

    arvindchetu

    Joined:
    Jun 3, 2020
    Posts:
    10
    I believe you can go with this approach, are you facing any issues in this technique?
    I mean this looks fine to me and many dev used this approach for basic locomotion.

    If you still wanna dig into it deeply you can go through this blog:-
    https://unity3d.com/how-to/build-animator-controllers
     
  3. gasguirre

    gasguirre

    Joined:
    Aug 7, 2018
    Posts:
    5
    Thank you very much, yes, it worked this time, the issue was the custom controller I had, that somehow was implementing a "smooth transition" but the values were jumping around all the time. I think that made the blending look badly.
    also, on top of it, I wasn't putting the proper avatar for the animation and that was also making it look super weird. thank you very much.