Tips and strategies for designing a 2D character controller for frame sprite animation

Hey Unity Cats,

I’m trying to learn more about 2D platform control schemes and I suspect that what I’m trying to do is going to require a very specialized controller–being a newb, I am not completely sure where to start.

Here’s my dilemma:

I have a simple frame-by-frame character sprite animation walking around a simple 2D background. Everything is hand drawn. I have a roughed out 8 frame walk cycle and a single frame idle loop for testing. The 8 frame cycle is stretched out to 8fps (so it’s rough, but feels about right timing-wise).

I’ve built a super simple character controller based on some tutorials I’ve seen (and most approach it similarly). Basically, I have a rigidbody 2d character which I apply velocity to as soon as I detect horizontal input from the player.

This is all fine and dandy and is very easy to implement. I use a switch to manage the animator and transition to a Walking state if my horizontal velocity is over or under 0 and switch out if it equals 0.

But I noticed a couple of things. One, the animation is slidey, even after trying to tweak the velocity factor to try to match the ground, it’s both slightly slidey during the animation and it’s especially slidey on the start-in and the ending. This is probably because there’s a slight acceleration and deceleration effect happening.

You can see video here:

I suspect that I will need to sort out some much more accurate method of applying movement for my player controller–maybe even measure the stride distance and some how use that information to control movement speed.

I also suspect, though I’m not sure, that I may need transition animations to smooth in and out of the walking.

Are these sound strategies for my scenario? Do you folks have any tips that might point me toward the light? I’d like a solid/grounded feel to the character movement, and of course, responsiveness is an ideal.

Here are a few things you can do:

1: Smooth in the animation. Some of the sliding is because of the rough animation. Our eyes are at least fast enough to see the character sliding in place multiple times at 8fps, it seems. One set of between frames would probably mostly fix it, but 8 fps actually isn’t that bad. I’m pretty sure your character needs to move significantly more quickly to match his foot speed at that framerate, though.

2: Configure the input axis. You’re correct that the acceleration of the axis causes some visual slip. One thing that also helps for games that need tighter controls is to increase the gravity and sensitivity of the axis significantly. You can also just make movement based on a button press rather than an axis. This might not be wanted for slower paced games.

3: Use a blend tree to change the speed of the animation. You can have your walking state in your animation controller be a blend tree that takes your character’s horizontal speed as input. Each branch of the tree is the same walking animation, but tweaked to various speeds. Configure the branch transitions to change evenly based on speed. The end result is a character whose walking animation speed follows its horizontal velocity.

You could do transition animations, too. They would look nice, but aren’t needed to fix your problem.

1 Like

These are really great directions, thank you!

I would imagine that calibrating the animation play speed with the character velocity would be a bit challenging–I would probably have to implement more inbetweens to keep animation smooth at slower speeds–but I really like the potential for analog manipulation of the character.

I could also set up a case switch to transition through movement types as well.

It sounds like ultimately, I will need to figure out some method of calibrating the animation against the movement speed–no way to dodge it.