Skip to content

gamedev-skills/awesome-gamedev-agent-skills / skills/unity/unity-animation

unity-animation

Verified

Unity 6.3 LTS character animation with the Animator (Mecanim): states and transitions, blend trees, Avatar Mask layers, root motion and humanoid IK. Use for SetTrigger wiring, a transition that lags or never fires, sliding root motion, or an upper-body layer overriding the legs. Not for AI state machines (`game-ai`), juice (`game-feel`) or Godot (`godot-animation`).

FileKindSize
SKILL.mdskill md8.9 KB
references/blend-trees-and-ik.mdmarkdown3.4 KB

references/blend-trees-and-ik.md

View on GitHub
# Blend trees, layers & humanoid IK (Unity 6.3 LTS)

Depth for `unity-animation`. Verified against the Unity Manual Animation section and
`ScriptReference/Animator`.

## Blend trees

A Blend Tree blends several clips by one or two `Float` parameters, so continuous motion
(idle → walk → run, or 8-direction movement) is one node instead of many states.

- **1D** — one parameter (e.g. `Speed`). Place clips along the axis (0 idle, 2 walk, 6 run);
  the tree cross-fades by where the parameter sits.
- **2D Simple Directional** — clips at distinct directions (forward, back, strafe).
- **2D Freeform Directional / Cartesian** — arbitrary clip placement in a 2D field
  (`MoveX`, `MoveY`); Freeform Cartesian suits non-directional pairs (speed × turn).

Drive it from script exactly like any float parameter, ideally damped:

```csharp
_anim.SetFloat("Speed", speed, 0.1f, Time.deltaTime);   // dampTime smooths the blend
_anim.SetFloat("MoveX", moveX);
_anim.SetFloat("MoveY", moveY);
```

Tip: keep blend thresholds matched to the clips' real root speed so feet don't slide.

## Animation layers + Avatar Masks

Layers let an upper-body action (aim, throw) play over a base locomotion layer.

- Each layer has a **weight** (0–1) and a **Blend mode**: `Override` (replaces) or `Additive`
  (adds on top of the base pose).
- An **Avatar Mask** restricts a layer to selected bones (e.g. spine + arms), so the legs keep
  walking while the arms aim.

```csharp
int aimLayer = _anim.GetLayerIndex("UpperBody");
_anim.SetLayerWeight(aimLayer, isAiming ? 1f : 0f);   // fade the layer in/out
```

## Humanoid IK (`OnAnimatorIK`)

IK adjusts hands/feet/look toward targets *after* the animation pose is sampled. Requirements:
Humanoid Avatar, and **IK Pass** enabled on the layer.

```csharp
[SerializeField] private Transform lookTarget, rightHandTarget;

// Called by the Animator once per frame, per layer, when IK Pass is on.
private void OnAnimatorIK(int layerIndex)
{
    if (lookTarget)
    {
        _anim.SetLookAtWeight(1f);                 // overall look-at weight
        _anim.SetLookAtPosition(lookTarget.position);
    }
    if (rightHandTarget)
    {
        _anim.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f);   // 0..1 blend toward target
        _anim.SetIKRotationWeight(AvatarIKGoal.RightHand, 1f);
        _anim.SetIKPosition(AvatarIKGoal.RightHand, rightHandTarget.position);
        _anim.SetIKRotation(AvatarIKGoal.RightHand, rightHandTarget.rotation);
    }
}
```

`AvatarIKGoal` values: `LeftFoot`, `RightFoot`, `LeftHand`, `RightHand`. Set the weight back
toward 0 to release the IK smoothly.

### Foot IK for sloped ground

- Enable **Foot IK** on the locomotion states.
- Raycast down from each foot, then `SetIKPosition`/`SetIKRotation` to the surface point and
  normal so feet plant on slopes instead of clipping or floating.

## Gotchas

- IK calls outside `OnAnimatorIK` are ignored.
- `SetLookAtWeight` has extra body/head/eyes/clamp parameters — the single-arg overload is a
  shortcut for the common case.
- Layer weights and IK weights are not auto-reset; lerp them toward 0 when disengaging or the
  pose stays stuck.
- An additive layer adds each clip's difference from its reference pose, which is the clip's
  first frame unless **Additive Reference Pose** is enabled in the clip's import settings.
  If that frame is not a neutral pose, the whole layer comes out offset; pick a neutral frame.
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall