- Home /
How to Sync the Running and Attack Animations for a 2D Sprite?
IF you look at the 2 and 4 row in the spritesheet that I provided, you will see that in the 2nd row the character is simply running while in the 4th row he is running and attacking at the same time. I wish to blend these 2 animations whenever the player decides to attack. I read about using avatar masks and creating separate layers to animate certain parts of the player's body for rigged 3D models but I'm not sure if I can take the same approach for 2D sprite. I would also like to extend so that player can also attack while idling. Any ideas how I can do it?
Answer by MaxGuernseyIII · Jan 13, 2018 at 07:27 PM
You are facing the same problem a lot of people face when programming. You can either blend everything together and have to attend to every combination of every value of every variable, or your can break a problem down into smaller problems and solve each one independently, then find a way to link the solutions together.
In programming, it's a "no-brainer". The only people who think breaking things down into more cohesive solutions is harder are people who haven't yet become accustomed to doing it that way.
I can't say whether it's better for sprites, although I suspect it is.
Anyway, the two solutions for sprites are as follows:
Mash the problem of running and attacking together by creating another row that is both running and attacking.
Separate the arms from the body and animate the arm separate from the body.
The exact details of that would be up to you but, at an high level, I would expect you to create multiple game objects, set the anchors of the dependent game objects (e.g., the arm) to be at the point where it connects with its dependency (e.g., the shoulder), then move the image according to where that connection point is on the dependency object (e.g., as the torso moves, change the position of the arm accordingly).
There might be a better solution. I know that Unity had a pretty neat live session about 2D sprite stuff.
https://unity3d.com/learn/tutorials/topics/2d-game-creation/introduction-and-goals
I remember there being multi-layered sprite characters in that.
Thanks for your input. I was thinking of doing it this way but then I thought of some simpler approach and I would appreciate if you gave me some feedback. $$anonymous$$y new approach is this. If you look at the spritesheet, you can see that both the "running" animations and "running and attacking" animations have the same amount of frames and they are both one to one in terms of similarity. What I can do is if I'm on frame 5 of the running animation and I start attacking, then the running and attacking animation should start at frame 5 and it would be a smooth enough transition. Probably not a long term solution but is something I just thought up.
That should definitely work and I can see how it's probably an inexpensive change.
I'm not sure it's "simpler", though, because it leaves what the arm is doing conflated with what the other parts of the body are doing. If add a new thing for the arm to be doing, you have to attend to all the cases where they might be doing it. If you add a new thing the rest of the body might be doing, you have to make sure your weapon-arm cases are all attended to for the new activity type.
Still, as a transitional change toward something more sustainably-cohesive, it makes a lot of sense.
Your answer
Follow this Question
Related Questions
Multiple Animation Controllers 1 Answer
SpriteManager 2 1 Answer
Sprite animation 2 Answers
Animation System in 4.3 1 Answer