Skip to content

ddhoa-dev/Unity-Procedural-Locomotion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🕷️ Unity Procedural Locomotion System

An advanced, dual-system locomotion controller for Unity, featuring a 100% Procedural Kinematic Walk for multi-legged creatures and a Native IK Foot Placement system for Humanoid characters.

🌟 Overview

This repository demonstrates two fundamentally different approaches to solving character locomotion in 3D environments:

  1. The Bug (Procedural Animation): A purely mathematical approach where no pre-baked animations are used. Every footstep, body tilt, and movement is calculated in real-time.
  2. The Humanoid (Data-Driven + IK Blend): Enhances traditional Motion Capture animations with Unity's Native IK to achieve perfect foot placement on stairs and slopes without breaking the original animation's artistic intent.

🐞 1. Procedural Walk System (Multi-Legged)

Target: Hexapods, Spiders, Mechs, Insects.

This system discards traditional Animator Controllers entirely in favor of a 100% code-driven State Machine utilizing complex Kinematics.

✨ Key Features:

  • Alternating Tripod Gait: Divides the 6 legs into two alternating groups. A strict logic gate ensures one group is firmly planted before the other can lift, perfectly mimicking real insect movement.
  • Parabolic Step Arc: Utilizes Sine waves (Mathf.Sin) to dynamically draw the trajectory of the foot mid-air. Step height automatically scales up to step over physical obstacles.
  • Kinematic Prediction (Future Yaw): Calculates linear and angular velocity to predict the character's future rotation. When cornering sharply, the legs will step outward to "catch" the turn before the body rotates.
  • Dynamic Body Alignment: Uses Vector Cross Products of the surface normals to dynamically adjust the body's Pitch and Roll. Features an auto-ground-clearance system to prevent the belly from clipping through the terrain.

🧍‍♀️ 2. Native IK Locomotion System (Humanoid)

Target: Bipeds, Humanoids (e.g., Hatsune Miku).

Instead of relying on external packages like Animation Rigging which often suffer from Execution Order conflicts (LateUpdate vs RigBuilder), this system hooks directly into Unity's core OnAnimatorIK pass for AAA-standard stability.

✨ Key Features:

  • Foot Lift Preservation: Doesn't just glue the feet to the ground. It calculates the vertical offset of the foot from the original FBX animation and adds it to the raycasted ground height, preserving natural heel-toe lifting mechanics.
  • Hips Counter-Offset: Automatically detects the distance to the ground and smoothly lowers the character's Center of Gravity (Hips) when stepping down stairs, preventing the legs from over-extending or floating.
  • Anatomical Knee Hints: Solves the notorious "Knee Popping" issue by projecting an IK Hint vector in front of the character, forcing the IK solver to bend the knees anatomically forward regardless of the terrain height.
  • Lag-Free XZ Tracking: Separates the Y-axis (which is Lerped for smoothness) from the XZ-axes (which are hard-locked to the animation) to eliminate foot-sliding when walking forward or backward.

🛠️ Technical Highlights & Learnings

  • Execution Order Matters: A major learning from this project was identifying why Third-Party IK solutions often cause feet to clip through the floor. Adjusting the character's root position in LateUpdate pushes already-solved IK targets underground. Utilizing OnAnimatorIK solves this natively.
  • Math vs. Art: Humanoid movement is highly expressive and requires Data-Driven animation (Mocap) blended with IK for realism. Conversely, insect movement is mechanical and highly terrain-dependent, making Pure Procedural Kinematics the vastly superior choice.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors