Chaotic Motion

This asset has been deprecated for now. It requires fixes in both 2019.4 and 2020 to adapt to changes in the ECS system (or I need to make the ECS code conditional). If you would like a refund, please email your purchase code to nbodyphysics@gmail.com

New in 3.0: Swarms of entities using ECS/DOTS! (This requires the  packages for Burst, Mathematics and the preview packages Entities and HybridRenderer) .

Unity 2019.3: Use the Package Manager to install the Burst and Mathematics packages. Then under Advanced, select Show Preview Packages and install Entities, HybridRenderer.

Unity 2020.1: Unity has removed the preview packages from the package manager. Following  Jeff Lynch they can be side-loaded from GIT. There are then issues with changes to the API and rendering of the entities that are currently being debugged. Contact nbodyphysics@gmail.com for an update. (Sept 29, 2020)

Scripting Documentation

Overview

Chaotic Motion is a Unity asset that moves game objects, swarms of game objects, entities and particles under the control of a chaotic attractor in 3D or 2D. A comprehensive library of 40 chaotic systems is available to choose from . The asset provides default values for all chaotic systems and allows the system parameters, time scale, physical scale and starting location to be adjusted. Make agents in your game move on a chaotic path, create chaotic targets or add mesmerizing chaotic particle effects to your game!

Sample Scenes

Chaotic Motion provides scenes that highlight how to use the asset.

ChaosJobSystemDemonstrate the creation of a swarm of game objects moved chaotically with the Unity Job System
ChaoticMotionDemonstrate a single game object moved by a Chaotic system with a ChaosTrail.
ChaoticParticlesDemonstrate a particle system evolved with ChaoticParticles.
GuardSimple example of two "guards" moving on a plane under ChaoticMotion control
JobSystemSlideshowSlideshow of each system using ChaosJobSystem
MotionSlideshowSlideshow of each system using ChaoticMotion
ParticlesBurstSlideshowSlideshow of each system using a burst of particles.
ParticlesEmitSlideshowSlideshow of each system using continuously emitted particles

Background

A Chaotic system is a system of mathematical equations that evolve in a pattern that does not repeat and varies significantly depending on exactly which point in space the system starts at. Two adjacent points will separate at an exponential rate. It can be proven that a chaotic system must have at least three variables. There is a vast literature on the subject. A popular historical account of Chaos is Gleik’s Chaos: Making a New Science (2008). For more mathematical details I have been using Sprott’s Elegant Chaos: Algebraically Simple Chaotic Flows (2010). An earlier work with some good background is Sprott’s Strange Attractors: Creating Patterns in Chaos (available as a PDF) .

Fundamental Components

Four key components are provided by the package:

  1. ChaoticMotion: Move the game object it is attached to according to the selected chaotic system.
  2. ChaosECS: Spawn tens of thousands of entities and evolve them chaotically.
  3. ChaosJobSystem: Instantiates and evolves a swarm of objects and moves them based on a chaotic system.
  4. ChaoticParticles: Moves particles according to a chaotic attractor.

These components all derive from a common base object: ChaoticSystem. The world scale, rotation and offset are all taken from the transform component attached to the object that has the Chaos component.

Chaotic Motion of a Game Object

To move a game object chaotically simply add the ChaoticMotion component to it. The inspector controls allow a chaos system to be selected. The chaos systems are named after the researcher who first discovered them, so it can initially seem to be a somewhat baffling list. Slideshow scenes in the asset provide a slideshow of the systems for swarms, objects and particles to allow the systems to be browsed.

The ChaoticMotion component will move the attached game object in accordance with the Chaotic System selected in the inspector using the parameter set provided. By default the parameter set is “default (scaled)”. This parameter set is tuned to scale the resulting motion to fit in a box roughly 10 units per side. Different options are available via the inspector:

Chaos System

Selects the chaotic system to use for the motion of the game object. Different systems will result in different types of chaotic motion.

The evolution of the chaos system takes place in a “physics space” internal to the ChaoticMotion component and is then translated in “game space” by using the initial position of the game objects and the evolution scale.  The range of the motion in physics space is dictated by the equations of the system and the specific parameters in use. In order to make these different systems easily usable in a game context – there is a “default (scaled)” parameter set that uses scale and offset parameters to provide chaotic motion within a 10x10x10 box. These parameters are explained below.

Tinkering with the system parameters and initial position will change the resulting path. If the object diverges to infinity the script will stop evolving the game object.

Equations

Shows the equations that define the chaos system selected. These may be useful when customizing parameters. It is not necessary to understand the equations to use the asset.

Parameter Choice

Sets of parameters are bundled together into selections in the parameter drop down. The default choice results in a “common” choice for parameters (meaning those typically used in research papers about the chaotic system). The scaled default adjusts the physics offset and scale to produce chaotic motion in a 10x10x10 box at the local origin.

Selecting custom allows the specific parameters in the chaos system to be altered. The parameters also allow for control of the offset of the origin of the physical system and its scale to be adjusted.

TimeZoom

Adjusts the speed of the evolution of the system. A value of 1.0 runs the system as described by the equations in their natural timescale. Systems vary in how quickly they evolve at different points in the trajectory. Reducing the value to lower than 1 (but greater than zero) results in slower motion in the scene; increasing results in faster motion.

ChaosECS

A swarm of entities is generated by the ChaosECS script. The entities will move according the selected chaotic system and will orient towards the direction of motion.

In addition to the Chaos System parameters described above it has additional parameters:

Number of Entities: The total number of entities to be spawned into the scene.

Add rate/frame: The number of entities per frame to be spawned at startup.

Mesh: The mesh to be used to render each entity.

Mesh Scale: The size of each mesh entity.

Material: The material to be applied to the mesh.

ECS Implementation

The ECS implementation in the ChaosECS script creates and entity with the following components:

  • ChaosComponent: per entity information/physics stats
  • ChaosTransform: map physics space to Unity scene
  • ChaosGroupComponent (shared): group ID
  • Translation: Unity ECS position
  • Scale: Unity ECS scale
  • Rotation: Unity ECS rotation
  • Rendermesh: (shared) mesh/material
  • LocalToWorld: Transform for local to world

Chaotic Motion provides the following ECS systems:

  • ChaosMoveSystem: Numerical integration of the chaos system
  • ChaosTransformSystem: Map from physics space to Unity scene
  • RotationSystem: Orient each mesh in the direction of motion

ChaosJobSystem

The ChaoticJobSystem generates a swarm of game objects and evolves them according to the selected chaotic attractor.

The Chaotic system parameters are the same as those described above for ChaoticMotion. The additional fields are:

Number of Objects: The number of game objects that will be spawned in the scene at startup.

Scatter Radius: The radius around the initial position that the new objects will be initially placed.

Prefab: The prefab for the game objects in the swarm.

Chaotic Particles

Chaotic particle motion can be created by attaching a ChaoticParticles component to a standard Unity particle system. The particle system configuration must:

  • have zero velocity for the particles
  • not render the particles as “stretched billboard”

The script will check for these conditions and log an error if they are detected.

The ChaoticParticles component takes control of the particle evolution, so parameters that adjust velocity and velocity over time will have no effect.

The Chaotic evolution is controlled by the inspector using are the same controls as the ChaoticMotion component. These are described above.

Chaos systems are by their nature very sensitive to the initial conditions at the start of evolution. Typically particle emission in a small region within the attractor produces interesting results, but feel free to experiment. In some cases particles will diverge to infinity and the script will stop evolving them.

Chaotic Trails

The Unity TrailRenderer component is useful to show the path a game object has taken. In some cases, its use with an object controlled by a ChaoticMotion script can result is a segmented appearance. This is because the trail renderer connects past positions with line segments and in regions where the object moves quickly, points in between are missed. The ChaosTrail component was designed to smooth out these segments.

The ChaosTrail script is typically attached to a child of the chaotic object. This allows the attributes to be varied independently. The ChaoticMotion component will detect any ChaosTrail components and update them during the physics calculations within a frame to maintain a smooth path behind the object. The parameters for ChaosTrail are:

Screen Shot 2017-07-09 at 12.37.32 PM

MinVertexDistance

Distance to be exceeded before a new point is added to the LineRenderer.

MaxPoints

Maximum number of points in the trail.

ChaosTrail relies on a game object and cannot be used in conjunction with entities.