Website powered by

Unreal Engine Niagara Particle System - Smart Crabs

Edit: A much more improved and stable version is now available as a Tier 2 reward on my Patreon: https://www.patreon.com/GhislainGir

Here's a particle system I created to learn Unreal Engine's Niagara particle system. Most of the techniques I used were inspired by this video that I strongly recommend: https://www.youtube.com/watch?v=CqXKSyAPWZY

Crabs were modelled and animated in Blender. Animations were baked into textures to use vertex animation. A custom state machine was built in Niagara to drive the crabs’ behaviours and animations. They flee the player (using a Niagara Parameter Collection to send the player’s location), avoid nearby obstacles (using Distance fields) and nearby crabs (using Grid 3D)

A cheap hack was used to make them stick to the ground (using virtual textures to project vertices onto the ground) because I couldn’t figure out how to do proper terrain collision. This issue is that a landscape in Unreal Engine automatically generates a Distance Field and so the nearest distance a crab will query is the ground underneath it and that completely messes up obstacle avoidance. I need to investigate a better solution but for now that trick works surprisingly well!

Niagara is insanely powerful and not that complicated when you take the time to really dive into it. I encourage everyone interested in it to give it a serious try :) A lot of great examples can be found and learned from in the Content Examples with UE 4.26. The future of particles is bright!

Crabs flee the player

Crabs flee the player

Crabs avoid obstacles

Crabs avoid obstacles

Skeletal animations are baked into textures to use vertex animation

Skeletal animations are baked into textures to use vertex animation

The good old shadow blob technique is used to make the crab cast a fake soft shadow

The good old shadow blob technique is used to make the crab cast a fake soft shadow

A custom state machine is built in Niagara to drive crabs' behaviours

A custom state machine is built in Niagara to drive crabs' behaviours

That state machine also drives crabs' vertex-based animations

That state machine also drives crabs' vertex-based animations

Debug view of those states. Green = Idle. Blue = Walk. Pink = Flee. Red = Unbury. Yellow = Bury

Debug view of those states. Green = Idle. Blue = Walk. Pink = Flee. Red = Unbury. Yellow = Bury

A simple material is used for crabs (and to create the debug view as well)

A simple material is used for crabs (and to create the debug view as well)

Record time and a new random state duration when entering a new state

Record time and a new random state duration when entering a new state

Kill particle if crab is buried

Kill particle if crab is buried

Crabs avoid obstacles using Distance fields

Crabs avoid obstacles using Distance fields

Crabs flee the player using a location vector given by a Niagara Parameter Collection (updated using Blueprints)

Crabs flee the player using a location vector given by a Niagara Parameter Collection (updated using Blueprints)

Crabs try to keep a satefy distance from each other

Crabs try to keep a satefy distance from each other

Repel force exaggerated here to see that they spread out to avoid colliding with nearby crabs (using Grid 3D)

Repel force exaggerated here to see that they spread out to avoid colliding with nearby crabs (using Grid 3D)

If we added velocity from obstacle, player or crab avoidance, a crab goes into flee state

If we added velocity from obstacle, player or crab avoidance, a crab goes into flee state

Crabs have a set amount of walk cycles allowed until they bury themselves underneath the sand

Crabs have a set amount of walk cycles allowed until they bury themselves underneath the sand

Making them flee is strangely satisfying :)

Making them flee is strangely satisfying :)