Skip to content

Repository files navigation

Dynamic Hair Bone

A lightweight Verlet-integration based bone physics system for anime-style character hair in Unity.

Wind Demo

Demo

License Unity

A simple, dependency-free hair/bone physics system built on Verlet integration and Position Based Dynamics (PBD) distance constraints — inspired by the approach used in Dynamic Bone and Magica Cloth, written from scratch for learning purposes.

Features

  • Verlet-integration based physics simulation (no Unity Rigidbody/Physics dependency)
  • Distance-constraint solver to keep bone chain length rigid
  • Gimbal-lock-free rotation using Quaternion.FromToRotation delta (no Transform.LookAt issues)
  • Branching bone chains supported
  • Per-chain tunable parameters: damping, stiffness, gravity, external force
  • Centralized HairBoneManager for batched updates across multiple hair chains
  • Editor gizmo visualization for debugging bone chains in Scene view

Installation

Unity Package Manager

  1. Open Window → Package Manager
  2. Click +Add package by name
  3. Paste:
    com.lovegraphics.dynamichairbone
    

Quick Start

  1. Rig your hair as a bone chain in Blender/Maya (root → tip), import as FBX into Unity.
  2. Add an empty GameObject to your scene, attach HairBoneManager to it.
  3. In the Inspector, drag the root Transform of each hair strand into the Root Bones list.
  4. Press Play — hair chains are auto-initialized and simulated in LateUpdate.
  5. Select the hair root in Scene view, enable Draw Gizmos on its HairChain component to visualize the bone chain.

Parameters

Parameter Range Description
Damping 0.05 – 0.3 Velocity decay per frame. Lower = more jiggle, higher = stiffer stop
Stiffness 0.1 – 0.6 How strongly bones are pulled back toward the animated pose
Gravity Vector3 Constant force applied every frame (chain-local, not Physics.gravity)
Force Vector3 External force slot for wind/gameplay effects, set at runtime
Constraint Iterations 2 – 6 Solver iterations for the distance constraint (higher = more rigid)

How it works

Each frame, in LateUpdate (after Animator has posed the skeleton):

  1. Capture target — read each bone's animated position as targetPosition
  2. Verlet integration — infer velocity from currentPosition - previousPosition, apply damping, gravity, and external force
  3. Pull toward animation — blend the physics result back toward targetPosition using stiffness
  4. Distance constraint — iteratively re-project each bone to maintain its original bone length from its parent (root → tip order)
  5. Apply to transform — rotate the parent bone using a rest-pose-relative Quaternion.FromToRotation delta (avoids LookAt gimbal lock), then set the child's position

Root bones always follow the animated pose exactly (stiffness doesn't apply to them) — only child bones simulate physics.

Roadmap

  • Sphere/Capsule collision against head & shoulder colliders
  • Editor tool to auto-detect bone chains from a selected root
  • Job System / Burst-compatible version for large hair counts
  • Per-bone stiffness gradient (root stiffer than tip)

License

This project is licensed under the MIT License — see LICENSE for details.

🙏 Acknowledgements

Built as a learning project to understand Verlet integration and Position Based Dynamics, inspired by publicly documented approaches used in Unity Chan Spring Bone, Dynamic Bone, and Magica Cloth.

About

A lightweight Verlet-integration based bone physics system for anime-style character hair in Unity.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages