mbrea-c / bevy_animation_graph

Animation graphs in Bevy!
Apache License 2.0
97 stars 5 forks source link

Inverse kinematics for two-bone chains #19

Closed mbrea-c closed 8 months ago

mbrea-c commented 8 months ago

Objective

Inverse kinematics is often used in game development for procedural animations or fine-tuning existing animations to fit the circumstance (e.g. make the hands correctly grip a weapon, or place the feet at ground height) among other reasons. The special case for inverse kinematics for two-bone chains fit most common use-cases, and is easiest to implement as it has a simple analytical solution.

Solution

Implement a two-bone IK node, which works on bone-space poses (this helps when applying it to bones that has descendants). This node accepts a pose, a bone target and a target position, and modifies the bone target, and its two nearest ancestors in order to place the bone target at the target position while keeping bone lengths constant.

Deferred rendering gizmos were added as a way to enable easier debugging of nodes. These gizmos are buffered and rendered by a system that runs after the animation graph is evaluated.