An interactive Lorenz attractor simulator in Unity 🎮, designed to explore chaos, the butterfly effect, and velocity dynamics in a visually intuitive way.
butt.mp4
Recording.2025-10-28.191557.mp4
- Numerical Integration: Uses RK4 (Runge-Kutta 4th order) for accurate time evolution of the Lorenz system.
- Dynamic Mesh Rendering: The attractor trail is drawn with a Mesh rather than a LineRenderer for performance (even with 25k+ points).
- Per-Point Velocity Coloring:
Visualize instantaneous velocity magnitude along the trail using a customizable Gradient 🎨. - Butterfly Effect Mode 🦋:
Slight rounding of initial conditions demonstrates sensitive dependence on initial conditions — chaos in action! - Compare Two Attractors:
Spawn multiple attractors (normal vs. butterfly-effect) to observe divergence over time. - Orbit Camera:
Smooth, mouse-controlled orbit camera that automatically centers on the active attractor points.
-
Setup Attractor:
- Create a ScriptableObject (
LorenzAttractorSettings) for each attractor. - Configure:
timeStepinitialPositionmaxPointsvelocityGradientenableButterflyEffect✅ to apply rounding to initial conditions.
- Create a ScriptableObject (
-
Add Attractor to Scene:
- Attach
LorenzAttractor.csto a GameObject. - Assign the corresponding
LorenzAttractorSettings.
- Attach
-
Camera Setup:
- Attach
OrbitCamera.csto your main camera. - Set
targetto one of the Lorenz attractor GameObjects. - Enable
Use Dynamic Centerto follow the attractor trail.
- Attach
-
Visual Exploration:
- Drag the mouse to rotate the camera.
- Scroll to zoom in/out.
- Watch attractors diverge in real time, colored by velocity magnitude.
- The Lorenz system is defined by:
[ \begin{cases} \frac{dx}{dt} = \sigma (y - x) \ \frac{dy}{dt} = x (\rho - z) - y \ \frac{dz}{dt} = xy - \beta z \end{cases} ]
with typical parameters:
σ = 10, ρ = 28, β = 8/3.
- Butterfly Effect: Small differences in initial conditions (here via rounding) grow exponentially, illustrating chaotic dynamics.
- Velocity Visualization:
Each vertex is colored according to the magnitude of its instantaneous derivative, showing where the system moves faster or slower in 3D space.
LorenzAttractor.cs— Generates and updates the attractor mesh in real-time.LorenzAttractorEquationsSolver.cs— Implements RK4 integration and derivative calculation.LorenzAttractorSettings.cs— ScriptableObject storing parameters, including butterfly effect option.OrbitCamera.cs— Smooth orbit camera centered on the attractor’s active points.
- Spawn two attractors:
- One normal
- One with butterfly effect enabled
- Observe divergence over time 🦋.
- Experiment with gradient coloring to highlight high-velocity regions.
- Increase
maxPointsfor high-resolution trails.
- Unity 2023+ (or compatible version)
- Standard 3D pipeline
- Optional: HDRP/URP for improved visuals