Question regarding animations. State machine or code wise?

Hi!

Lately I’m trying to extend my experience with Unity by diving into different topics and creating something with it. This time I’m busy with animation with mecanim. I really like the system and I think it works really well, but I think I’m not able to use it well enough for my current problem. I get how the system works and I can get create basic animations, but I wanted to go a step further.

So, I found this sprite sheet which has a lot of animtions to make movement look really smooth. Notice for example the these animations, which are played one time between looping animations. For example: Dashing (looping) → Transition into skidding (once) → Skidding (looping) → Stop skidding (once) → Idle

Anytime during these animations, looping or played once, the user could give other input, for example he could start jumping or shooting, which have their own path of animations that are played once or are looping. This means that from any animation I need to make a macanim transition towards any other possible animation. Which is a lot!

I know there is an Any State state, but I haven’t gotten that to work really well with what I’m trying. Here is a screenshot of my current animator: Screenshot - 8cb8034eb79d29f49cccc5580eb5d304 - Gyazo

So my question is, can I make use of mecanim more efficiently or should I do this kind of animation by code? Any tip, trick, feedback, help or opinion is appreciated! :slight_smile:

I would use layers for shooting and weight them so the animation has precedence

There are decent animation tutorials on youtube with mechanim

You could also use code for player animation state tracking using Interfaces/Classes and Enums to make state transitioning easier

There is a tutorial video on it for enemies on the unity3d site just google for “USING INTERFACES TO MAKE A STATE MACHINE FOR AI” its in the unity 3d site / tutorials / scripting

1 Like

I’ve looked a few Unity tutorials about animation, and came across sub-state machines. I think this is what I need!

I’m going to give that a try, thanks for the reply. :slight_smile: