Today I learned
Why does my procedural arm IK flip the wrist or jump between frames?
· updated #Game development
An arm solver that places the elbow and wrist from scratch every frame is correct per frame and still twitches: a wrist twist of +170° and −190° look the same to the solver, so it picks either one and the hand spins half a turn between two frames.
What fixed it for me, in order of impact:
- Choose the twist nearest the previous frame, not the "canonical" one.
- Cap the change: elbow swivel and wrist twist move at most 25° per frame.
- Hold the hand where it was last frame before the solver gives up and sends the arm home.
- Give the body collision a small tolerance. With zero, an elbow grazing the belly by 5 mm pushed the whole arm half a metre sideways. 8 mm of skin-on-skin allowance stopped that.
def unwrap(angle, prev):
# pick angle + k*360 closest to prev
return angle - 360 * round((angle - prev) / 360)
def step(angle, prev, max_step=25.0):
a = unwrap(angle, prev)
return prev + max(-max_step, min(max_step, a - prev))
Hit this while generating animation clips in Blender with Python for a game's characters: frames with an arm bone turning faster than 30° per frame dropped from 703 to 383 on one character. Apply each smoothing step only if the arm still stays outside the body, or the smoothing pushes the hand back inside.