Avatar


GLM Pipeline Hub

Crowd Disperse

An interactive real-time crowd simulation with complex behavior.

Tools: Unreal Engine, Niagara, Houdini


Problem

Running interactive crowd simulations in games can prove to be difficult due to complexity in behavior, size of crowd, and rendering them in real time.


Solution

Crowd Disperse is a Niagara-based crowd simulation in Unreal Engine 5. The simulation utilizes a state machine, distance fields, and flocking-inspired ideas.

GLM Pipeline Hub

Emulating Crowd Behavior

Every particle falls into one of three states- Idle, Walking, and Fleeing.

When the Idle state is entered, a random duration for how long the particle will spend in the state is generated. The particle does not move while in the Idle state.

Upon entering the Walking state, a random duration for how long the particle will spend in this state is generated. In addition, the particle is given a random direction to move towards. The particle is always moving while in the Walking state.

Particles enter the Fleeing state it senses "danger" within a distance threshold. This "danger" is defined by an inputted position parameter that is used to notify the particle system where the danger is happening. Particles can also sense danger from other particles. If particles sense nearby particles in the Fleeing state, they will begin to flee as well.

GLM Pipeline Hub

Collision Avoidance

Particles use global distance fields to avoid meshes, and flocking paired with Niagara's NeighborGrid3D to avoid other particles.

Particles use obstacle avoidance to avoid colliding with meshes in the environment. The particle's field of view is defined by 3 sphere traces to detect global distance fields on the CPU in front of each particle. The direction the particle is moving in steers left or right, depending on which sphere traces successfully hit.

The simulation uses flocking concepts to avoid other particles. In standard flocking demonstrations, particle's find nearby particles by calculating distances between every particle in the simulation, but that can be very costly on performance. Optimizing this using Niagara's NeighborGrid3D, every particle gets filled into different boxes in a grid. When calculating distances between particles in the simulation, it only does it between particles in neighboring boxes in the grid.

GLM Pipeline Hub

Vertex Animation Textures

Particle animations use shaders and VATS baked out from Houdini.

Using skeletal meshes for animations in Unreal Engine for crowds is costly on performance. By baking down the animations into position and normal textures, you can run these animations through shaders in Unreal.

To get the baked down animation textures, I use Side Lab's Vertex Animation Textures node in Houdini.

GLM Pipeline Hub

Performance Results

Testing the simulation with a 797 vert character mesh in editor, the system maintained 60+ FPS until particle counts exceeded 6,000.


Limitations and Future Work

This crowd simulation currently only supports flat terrain. In future iterations, particles can be projected onto the terrain using distance fields.

The crowd simulation's particle avoidance does not take into account field of view. As a result, particles may respond unrealistically to other particles besides or behind them.


Credits

Character Mesh by Maggie Rose

Character Rig and Animations by Endlessette Osborn

Senior Discount developed by the rest of the team at Blobs Games