Jump to content
  • Advertisement
Apjue

C++ How to have a good looking character animation?

Recommended Posts

Posted (edited)

Hello, I'm working on a 2D isometric game, and my character's animation doesn't satisfy me: The character kind of slips on the ground.

The animation looks like this (with this animation file). The code is similar to this:

// Moving character at south east
character.pos.x += 8; // pixels
character.pos.y += 4;
++character.animation.frame;

Do you have any tips to improve it?
Thanks

Edited by Apjue

Share this post


Link to post
Share on other sites
Advertisement

Analyze the image, determine how far the feet move between consecutive frames (relative to some "root" position, like the center of their head or something). Store that offset with the frame data, move the character only that far each frame.

For the five frames below, I drew a line from the player's nose to the tip of their left (backwards-moving, and therefore "planted" and presumably unmoving foot). In frame #1, it's at +1x from the nose. In frame #2, it's at -9x, and therefore moved -10x. So, when driving the character, the player's sprite should move forward by about +10 pixels. One frames #3 and #4, the toe is at -14x and -19x, so the character should move forward by another +4 and +5 pixels, respectively, before those frames.

Naturally, you'll want to use that as a guideline; the player won't be moving directly east unless they are snapped to the grid, so you'll want to move the player in their precise travel direction vector, normalized and then multiplied by the magnitude measured by this process.

image.png.18ca961293d45487260cff99e02cd56a.png

 

If you're lucky, the person who made the animation used the same animation viewed from varying angles, instead of making eight bespoke animations, and so the magnitude of the foot's movement will be the same in all the rotations. Remember to account for the projection (10px in X is 5px in Y if the projection ratio between X and Y is 2:1).

Share this post


Link to post
Share on other sites

Professionally-done animations are all using animation tools. You should not hardcode animation deltas in your code. You are already having issues animating one object, what do you think is going to happen when animating hundreds more different types of objects?

Share this post


Link to post
Share on other sites

Thanks for replying, I understand your solution Wyrframe but it is quite long to hardcode animation deltas, as said alnite

I don't know if the animation was done professionally, I found it for free and no 3D model file was provided, is it the only possible solution?

Share this post


Link to post
Share on other sites

It's definitely going to work at least.

Basically you want one foot to stick to the ground. As a first guess, I'd say it's the lowest foot, and the "back" one if there is a choice.

Maybe you can write a program that finds that foot in each frame and then compute offsets relative to it. Obviously this is not going to work 100%, at least when changing foot something has to be done (but a simple heuristic may work, eg don't move too much).

A simpler option could be to write a program where you align each frame on top of the previous frame manually, if the computer assists you eg like above, or by extra-polating movement in some way, it may be faster.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!