The following Godot 4.5 code demonstrates a way to have an animation transition so the new animation starts when a new frame would be drawn, rather than between frames. I made this since snappy animations (for example going from running to idle) feel janky in many games, and are often quite distracting. The FTH is easy to implement, and works well with state machines as well as simple systems.
After running the scene, press or hold space / left mouse button to switch to a bopping animation. Release to switch back.
- To prime the fix, check is set to true. For example, when you want to switch from walking to idle, check is set to true when the movement button is released.
- When certain conditions are met, the FTH is started. My conditions are:
- Check is true,
- The second to last frame is active,
- the frame has just been changed,
- The action button is not being pressed.
- Check is set to false to stop the statement endlessly repeating.
- The wait time of a timer is set using the animation speed and delta, then the timer is started.
- After the timer ends, the "_on_animation_smoother_timeout" function activates, which holds the logic for animation changing. 7.The timer is stopped and the animation is switched.
- On entry to a state, set check = true.
- Put the code for step 2-4 in the state's update function. I'd recommend checking if the previous state was one that you want the animation fix to work for unless you want to use it with every animation (... and PLAYER_INFORMATION.last_state in anim_fix_group).
- Do the remaining steps as usual.
If you want to make the animations even smoother, you could create transition frames that play after the fix completes.