How to animate a character freely aiming up and down

Hi guys,

Almost total amateur to Unity but not to programming.

I’m working on a character in a side-on view that walks left and right, but up and down (or the mouse or whatever else) control the character’s aim. I’m not sure of the best way to animate this—I already have about 20 sprites for the character aiming, but I can’t easily put that in an animation as it would just play through.

I thought the best way might be to keep each sprite separate and just swap back and forth as the player aims up and down in an array or similar. That would work but I’m not sure how I’d represent that in my current animator controller for the Prefab. I also thought of trying Sprite Swapping, but I haven’t looked into that too much yet.

As I’m just starting and this is a key component, I definitely want to go about this in the most logical and technically sound way possible, rather than trying to hack this functionality in. I couldn’t find a great tutorial for something this specific so I thought best to come here and ask. Any advice would be hugely appreciated!

I guess it has a lot to do with your design of the 2D character.

Is it enough to have the arm and gun aim upwards? then you’re done! But he might look funny standing vertically and pointing his arm straight up.

Perhaps you break the character into upper and lower animated parts, then you can lean the upper part backwards slightly as the aim rises, or even lean forward as he shoots down from a ledge.

Alternately have a set of X canned versions of your sprite, one for each possible aim angle, where “each possible” is obviously a number you can manage. To start with it might be one for horizontal, and one each for up and down 30 degrees. Or more…

I already have about 20 sprites for aiming up and down, and I can approximate transitioning from one to the next as the player aims. I’m leaning towards making a sprite array, but I’m not sure how I’d integrate that in with the animations in the animation controller.

There is this functionality:

https://docs.unity3d.com/Manual/class-BlendTree.html

which I suspect could be useful to you. You may need to separate your sprites into upper / lower parts to take full advantage of it, eg, combine standing, walking, running, jumping with all flavors of aiming.

So I’ve already used a Blend Tree initially; I made aiming up and down clips for four variants (aiming up to down on the left, down to up on the left and both mirrored on the right) but I couldn’t figure out how to incorporate free movement in with the animation clips. Right now, one animation will trigger and play in its entirety irrespective of where the player actually aims.

Is there a feature or option in the Blend Tree that I’m missing that would do what I’m describing? I had a fiddle with it but couldn’t figure anything out.

I believe it may be doable with Animation Layers.

But I could be wrong because I’ve never used these layers.

Just to clarify what I mean by free movement, I don’t mean something like legs moving freely while the upper body aims up and down. I mean the act of aiming controlling the animation, rather than the act of aiming up any amount triggering the ‘aim up’ animation.