Search Unity

help with animator controller logic for different jumps based on walk/run/idle state

Discussion in 'Animation' started by stain2319, Apr 15, 2021.

  1. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    417
    Hi,

    I am hoping to get some input and opinions on the best way to design an animator controller. I am getting into the weeds a little bit with all these different bools and trying to track various states like isRunning, isWalking, and thinking there must be a simpler way to structure this that I am missing.

    Essentially I have two blend trees for 8-direction walking/running animations. The blend trees get toggled between based on isRunning, e.g. one tree is for the walking animations, and if you are running it plays the running animations instead. This is working well and I also have an idleJump that is working well with a 3-part start/falling/stop animation, but where I am getting into trouble is with trying to add 2 more jump states for walking and running.

    I am using a combination of bools for isRunning, isWalking, a trigger for Jump, and a bool for didJump (to differentiate between falling and jumping) and it's not really working well in the run/walk versions, the jumps aren't as smooth as I would like to be and I think it's in part because of juggling around all these weird states.

    Any advice? Would it make sense to have different triggers, like IdleJump, WalkJump, and RunJump and just call these from code depending on the character state? Or is there something I am missing?

    I also would like the character to fall off cliffs and go from e.g. walking->falling->walking, or running->falling->running depending on whether they were holding down the run/movement keys when they land. Should I have a separate "falling" state or is it sufficient to link into the falling loop in my jumping sub-state machines?

    I welcome any ideas/thoughts/suggestions on how to properly structure these things. Seems like there is no "wrong way" but I am looking for an effective way that doesn't seem like too much spaghetti... :)
     
  2. launzone

    launzone

    Joined:
    Dec 2, 2015
    Posts:
    57
    I think its a bit hard to understand all your pieces in a paragraph since you describe already having trouble keeping up with everything yourself :).
    Anyway, I'll just try to describe some more general principles that i use when controlling more complicated animation state machines, not saying that this is 100% the way to go of course!

    Sounds like you are already doing the right thing with blend-trees for walking/ running. I don't understand why the bools come into play though (isRunning/ isWalking). From what i understand, you could just have another blend-tree that controls what amount of running/ walking is playing based on the characters velocity.
    Usually i don't use bools at all to control animation states but rather have an int parameter to only ever have one definitive state (for example, if there are no inputs/ movement the parameter gets set to 0 and the state-machine goes to idle if i set up the transition in the right way, then if the player hits jump the state goes to 1/ jump then when the jump animations is done playing or the y-velocity is negative and the character is not grounded it goes to 2/ falling, etc....)
    Similarly to the walk/ run tree you could also blend between different animations of jumping up and falling down based on the players velocity (both horizontal and vertical).
    In the past i did the transitions way too complicated in annoying spiderwebs but then figured out that most of the time it is fine to just have most animations (with some exceptions) transition from "Any State" and also let them transition back to that.
    Hope this spaghetti that I contributed is more helpful than confusing. Good luck!