Handmade Hero » Forums » Code » Animation, interploation and keyframes
boagz57
Jason
52 posts
#16598 Animation, interploation and keyframes
3 weeks, 6 days ago Edited by Jason on Oct. 24, 2018, 3:47 p.m. Reason: Initial post

My current understanding of how game animation works is the animator will mark specific key frames (in an animation package) of an animation at specific times that mark specific poses of the animation to be played. So at .5s, since animation start, a certain pose of the animation should be displayed. During runtime, as the animation is playing, if the games framerate is off a bit and it asks to display the animation at .6s then typically the engine will interpolate the animation from the key frame pose at .5s and the next key frame pose, say at .7s, to display an in-between frame.

If this understanding is correct then wouldn't this mean your exact key frame pose would be missed and not displayed? So if the animation was a punch animation then that means the height of the punch's impact which was on a key pose would be missed? Does this mean it's good to extend and accentuate animations for a certain amount of frames if they are frames important for things like collision detection?
mrmixer
Simon Anciaux
481 posts
#16599 Animation, interploation and keyframes
3 weeks, 6 days ago

In my experience keyframes are most of the time close enough that missing one will not degrade the animation much visually (if you only skip a frame or two). I depends on the style of game/animation but the animator can make a pose longer in the animation (by duplicating the keyframe or part of it across several frames for example) if he want to make sure that the pose will be seen. If an important pose lasts only one frame, the player will most likely not perceive it anyway since 16ms is too fast to distinguish it in the interpolation.

Some fighting games (like street fighter) have a small freeze/slow mo whenever a character hits another to highlight the punch (and I guess give some reaction time to combo). And since the hit windows is tied to the animation, it ensure that the pose is quite visible.

Depending on the game you are working on, the collision detection may be totally separated from the model animation. Here are some video from street fighter that show how hitboxes work:
Street Fighter V - Detailed tutor... hitboxes (Using Frame Trapped V)
Street Fighter V AE Sagat slow motion hitboxes
Opinion: Street Fighter 5 Hit Boxes

Another thing is that collision detection is often done at a higher frame rate than animation and at a fixed frame rate precisely to avoid frame rate issues.
boagz57
Jason
52 posts
#16600 Animation, interploation and keyframes
3 weeks, 6 days ago

Okay, so if collision detection is separated from animation, how do games ensure that the hit box coincides with the animation consistently? Wouldn't this leave in the possibility that the player won't see the peak of the hit animation but still feel the effects of the hit since the hit box will still perform correctly?
ratchetfreak
413 posts
#16601 Animation, interploation and keyframes
3 weeks, 5 days ago

That's what artistic liberty will solve. Holding the "impact" pose for a bit longer than necessary, exaggerating poses, windup and follow through, forcing a keyframe to appear anyway, ...

They are all very important to the feel of an animation.

In many cases the programmer will visualize the hitboxes and slow the game down to fine tune stuff.
mrmixer
Simon Anciaux
481 posts
#16602 Animation, interploation and keyframes
3 weeks, 5 days ago

boagz57
if collision detection is separated from animation, how do games ensure that the hit box coincides with the animation consistently?


It depends on the game, the engine, the programmer and whomever is responsible to make the system work.

For example in Unity (if I remember correctly) you can add markers in the animations that will be triggered when the animation reach that frame and you can use those in code to enable/disable a hitbox. In that case the animator could be the one tweaking things to make it good. In this case collision would still be pretty tied to animation.

You could have code separated from the animation that would handle a timeline to enable/disable the hitboxes. Animation and the hitbox timeline would start at the same time. A "game designer" could tweak the timing and the animator would need to adapt it's animation to those timings.

This will most likely be an iterative process between the designer, animator and programmer. As ratchetfreak said, visualization is important to make things right.
boagz57
Jason
52 posts
#16604 Animation, interploation and keyframes
3 weeks, 4 days ago Edited by Jason on Oct. 26, 2018, 3:21 p.m.

I see. So it seems its easier and more straight forward to tie the collision in with the animation but you then run the risk of missed collisions during frame hitches. On the flip side you can get more consistent collision detection by separating the mechanisms but this can cause more work for the animator as they try and match collisions and animations. Are there any other pros/cons to these methods that one should be aware of? I ask because I'm currently implementing a 2d fighting game myself and right now I just have 4 vertices bound to each fighter's body part through my animation program (spine). So these bounding boxes are just moving with the animation in local space and when I want to mark them 'active' in my engine I calculate their world space positions to test for collisions.
mrmixer
Simon Anciaux
481 posts
#16606 Animation, interploation and keyframes
3 weeks, 4 days ago

I only worked on a 3d fighting game prototype (combat was not limited to a 2d plane) that did none of those solutions (hits were "character state" + distance based) and it was very bad. So don't take what I say as a fact.

I think you should try to simulate frame drops to see what impact it has on the gameplay. If possible try both versions to see what work best for your game and team. If your engine has a way to record input and replay them in slow motion it could help visualize things. One advantage of separating the collision from the animation is that you can simulate the collision detection at a higher fixed framerate without having to update the animation. It would also keep the exact same collisions if the artist decides to change the animation a little. Another possible disadvantage of tying the collisions with the animation is that if the user disable the vsync (causing smaller delta between frame) the collision detection could vary.

That said, achieving constant 60fps should be a top priority in a 2d fighting game. In my opinion, consistency in the collision in case a frame misses is more important than visuals. Experienced fighting game player know the frame data (if that's the correct term) of their character and know what should hit at what distance without needing to view the animation.
boagz57
Jason
52 posts
#16607 Animation, interploation and keyframes
3 weeks, 4 days ago

mrmixer
That said, achieving constant 60fps should be a top priority in a 2d fighting game. In my opinion, consistency in the collision in case a frame misses is more important than visuals. Experienced fighting game player know the frame data (if that's the correct term) of their character and know what should hit at what distance without needing to view the animation.


Wow, great point. That's definitely a good case for separating animations and collision detections. Thanks for the advice.