Procedural Hair Simulation

hey everyone

recently as yk i created cloth and fluid simulation ( if you wanna check that out here ) and i decided now, i wanted to make hair simulation

the goal with this project wasnt really to make a game feature, but more to explore how secondary motion systems work in modern games and learn more about:

  • verlet integration
  • constraint solving
  • procedural generation
  • collision handling
  • vector math
  • physics based animation

the inspiration for this heavily came from gta6 lmfao, where as yk things like hair, clothing, and accessories react naturally to movement instead of just following animations

this entire system is fully custom and built from scratch in luau


procedural hair simulation

features

  • verlet integration
  • distance constraints
  • bending constraints
  • wind forces
  • character acceleration response
  • rotational inertia
  • collision capsule handling
  • procedural strand generation
  • hair clumping
  • wetness simulation
  • dynamic physics properties
  • procedural hair rendering

showcase

( and yes i attached the cloth from the last simulation to my back to make a cape sorta thing )


the hair is simulated as multiple strands made up of connected particles

each strand is basically a chain of points connected together by constraints

example:

particle
    |
particle
    |
particle
    |
particle

each frame the particles are updated using verlet integration, then the constraints are solved multiple times to keep the strand together and prevent it from stretching apart

the root particle is attached to the character while the rest of the strand is free to react to forces like gravity, wind, and movement


physics behavior

the hair reacts to:

  • character movement
  • sudden stops
  • turning
  • head rotation
  • wind
  • gravity
  • collisions
  • environmental changes

when the character accelerates, the hair lags behind due to inertia

when the character stops moving, the hair continues moving for a short time before slowly settling because of damping

this creates the natural secondary motion you see in realistic games


wet hair simulation

one of the features i added was a wetness system that changes the physical properties of the hair

the hair has two different physics states:

dry:

  • lighter movement
  • higher stiffness
  • more wind response
  • less clumping

wet:

  • heavier movement
  • lower stiffness
  • reduced wind influence
  • stronger clumping
  • increased gravity influence

wetness smoothly transitions between these states instead of instantly switching

this allows things like rain or water effects to actually change how the hair behaves


in case for the math nerds heres how the simulation works

verlet integration

instead of directly calculating velocity, the simulation stores the previous position of each particle

velocity is approximated by:

velocity = currentPosition - previousPosition

then the next position is calculated using:

newPosition =
currentPosition
+ velocity
+ acceleration * deltaTime²

this works really well for cloth, hair, and other soft-body style simulations because it is stable and easy to apply constraints to


distance constraints

each particle in a strand tries to maintain a fixed distance from the next particle

example:

A ------ B

if the distance becomes too large or too small, the solver calculates the error and pushes the particles back toward the correct distance

basically:

current distance vs target distance

fix the difference

this keeps the hair from stretching infinitely


bending constraints

distance constraints alone allow the strand to fold in unnatural ways

so bending constraints check multiple particles at once:

A ------ B ------ C

the middle particle is adjusted based on the direction of the surrounding particles to keep the strand from becoming too floppy

this gives the hair a stiffness value similar to real materials


collision capsules

to stop hair from passing through the character, the system uses custom capsule collision

instead of relying on roblox physics, the hair checks the closest point on a mathematical capsule representing parts of the body

if a particle enters the capsule radius, it gets pushed back to the surface

this allows the hair to interact with:

  • head
  • shoulders
  • body

while staying fully inside the custom simulation


rotational inertia

when the character rotates, the hair does not instantly follow

using angular velocity and cross products, the system calculates the force created by the rotation

this creates the delayed “hair toss” effect when turning quickly


procedural generation

the hair is generated mathematically instead of being manually placed

using spherical coordinates:

x = radius * sin(phi) * cos(theta)

y = radius * cos(phi)

z = radius * sin(phi) * sin(theta)

the system distributes strands around the head automatically

this allows different hairstyles to be created by changing values like:

  • density
  • length
  • spread
  • segment count
  • stiffness

why i made this

i lowk just wanted to create more physics simulations lmao, cuz their fun to make and watch

Could we see a video?