Looking for a better way to achieve my animations?

Hi, I’m a beginner to Unity and game development so I’m sorry if my question and current methods sound silly.

I have a multiple sprite character with four different sheets of art I created in Adobe Illustrator. The art separates the character’s limbs where I can piece them together in my scene. Assets from all sheets are placed as a child to an empty Player object. I created animations inside of Unity using the animation tool for idle and walk animations when the player faces left, down, up, and right.

A major issue I encountered was that even though I made basic transitions for the player moving/idling up and down, the player does not transition into the animation that I want. While PlayerUp and PlayerDown objects exist in the scene, they will individually complete their animations as intended, but the player facing up will not transition to move down and vice versa.

After watching many tutorials and google searching, I could not find a solution that was viable or simple enough for me to understand. My temporary fix was to stack the objects where the character is facing up and down on top of each other, and for example, when the player is facing the camera, having the objects where he is not facing the camera scale to 0 on the X and Y axis in the animation tool.

My idea gets the job done for now, but I realize that it is only an illusion since as soon as I end my game, all four character objects are visibly stacked on top of each other. This method could be tiresome when I want to move on to add more animations for when the character attacks, gets hit, dies, etc.

Is there a more efficient means to do this? Is there a tool in Unity I can use, or a simple script I can implement? Should I pursue animating software outside of Unity?

Any feedback or help would be appreciated. Thanks!

In your first attempt, were you using an Animator controller (Mecanim)? It’s hard to visualize what’s going on, but it sounds like there might be a misunderstanding of how it’s intended to be used. Why you have separate objects for up/down, for example, is a bit confusing to me.

I gather that you’re having trouble with your transitions, though. Are you sure you set the exit conditions in each transition correctly? If the exit states depend on a parameter such as a trigger, have you passed the values to the animator from your scripts?

Can you post a screenshot of your animation web or a .gif of the problem in action?

1 Like

I think I am very confused as well with how the animator is intended to be used…all the animations were done with the animator controller. The idea behind separate objects facing up and down was to have the character facing a different direction depending on which way he was moving. Here is the image of the issue:

For each direction the character isn’t moving, I have all the other objects deactivated from the animation. But as soon as a new transition occurs, the other objects are quickly flashed back into the game, perhaps because the Player object is always active?

If I set the transition time to 0, this issue doesn’t happen, but then there isn’t a smooth transition from the character walking to going into idle. Here are images of my animation web and one for the blend trees that determine movement and idle:

2677276--189052--Capture.PNG 2677276--189053--Capture2.PNG 2677276--189054--Capture3.PNG

Try removing your game object activation from your animations and handle them in a script instead. Sometimes interpolation in blend trees can cause weird effects with boolean values.

1 Like

OK, first, you should not be using separate objects for each direction. (Reminds me of the old joke about the guy so rich, he keeps four limousines — one for each compass direction.)

Unity’s animation system is very powerful, and of course you can do your entire game with it (using just one game object for your main character, and as many states and animations as you need).

However, the animation system was really designed for 3D models that are deformed (via bones) in between animation frames, or to blend from one state to another. For sprite-based animation, blending doesn’t make much sense in most cases. And then I find the whole animation controller thing to be quite a bit harder to use than it should be.

Please check out my article on animation methods in Unity, and if there’s anything there you don’t understand, let me know. You’re currently using method 3 (and I have some tips for using that correctly with sprites — such as proper use of the Exit Time and Transition Duration properties). But you might want to consider method 2 (which uses Unity animations, but without fiddling around so much with the animation controller) or method 1 (which replaces Unity’s animation system entirely with a simple script that just plays sequences of sprite frames).

1 Like

I am starting to think that my knowledge of Unity scripting needs to be greatly improved. Unity is not as simple of a tool as I had originally anticipated. Looking up individual solutions for each challenge that comes up seems like it will be a highly ineffective way to design my game.

Thank you for providing your excellent article. As I brush up on my scripting knowledge, I will definitely be referring to your resource to work on a solution, most likely implementing your code-driven animator approach.

As for my case, my sprite is based off of several body components that are pieced together, with each body part animated depending on the direction the player is facing as opposed to animations from within a sprite sheet. I understand now that having four separate game objects under one parent was a bad idea. Do you have any suggestions as to how I can structure my player object using the method of individually animating the character’s components based off of a given direction’s graphic asset inside of Unity?

The .gif I tried to post didn’t seem to go through, but here is an idea of what I am working with:

https://www.youtube.com/watch?v=RoV8GZtVeoI

I truly appreciate all of the feedback so far. Thank you guys!

Ah! I see. This is a different case indeed. With your character built out of components that way, you probably do want to use Unity animations. This will let you blend smoothly between animations, and is in fact the sort of thing the Unity animation system was designed for.

(My article is based on the more old-school style of animation, where you have a separate hand-drawn frame for each pose.)

I haven’t done very much with this style of animation, but I think you want to keep a single hierarchy of body parts, and just switch out the actual sprite on each body part when you change direction. You can of course animate each SpriteRenderer’s sprite value just as well as the orientation, position etc. of each form. So this ought to work fine.

Hey Joe, I started using your 2nd method for my sprite-based game but I couldn’t quickly figure out how I would code an exit time for certain animations. If it weren’t for that I would definitely prefer the 2nd method. Any advice?

I think you’re asking, how to have certain states in your (code-based) state machine time out, and automatically proceed to some other state?

You just look at timeInState in the ContinueState method, and when it’s big enough, call EnterState with the next state.

What I like about this approach is that these rules are so easy to read and write - clearer to my eyes than a bunch of conditions in the Animator state diagram (especially when your condition needs some ands and ors!).

Oh ok, got it, thanks.