Last year I got to work with Undead Labs on State of Decay 2. I was only on the project a short time on environment effects, impacts, and some muzzle flashes, but it was a lot of fun. By far the coolest thing I did was this little bug system blueprint. This Abzu GDC Session talks a bit about the same techniques I used here.
Here’s a gif of the final result:
All we really have for particles interacting with the world is collision. For things like dragon flies, grasshoppers, flies, and birds, we didn’t really need to get too fancy. But for things like cockroaches, rats, spiders, lizards, and really anything creepy-crawly that actually creeps and crawls, we’d need something else.
I started by animating the bug particles as if they’d always be on a flat surface, like so:
Then I created a Blueprint that takes a snapshot of the SceneDepth using a SceneCaptureComponent2D (on construction; you could do it at run-time, but I’d be wary of doing it per frame). In this picture, you can see a preview of the SceneDepth snapshot:
In the same blueprint, I put in a Particle System parameter so you could swap with any bug you’d like (tarantula, cricket, dragonfly, etc). I also created and set a Dynamic Material on that Particle System per emitter. Now, I could take the SceneDepth texture and add it to the WorldPositionOffset in the Dynamic Material. You can do this either per particle or per vertex, so I added a lerp that blended between the two called “Vertex Conformity.” Lizards and rats are squishy, so they had a “vertex conformity” of almost 1, each vert hugged the surface of the geometry. Cockroaches and spiders were set closer to 0, so they retained their shape.
Vertical areas are where this technique kinda falls apart, as you’d imagine, so be aware of that if you wanted to use this technique in your game! You can even see it a bit in my own gif when rats and lizards get extra long on the more vertical-parts of the rocks:
In addition to the vertex offset based on the SceneDepth, I also animated the pieces using vertex colors as masks. Giving them each their own unique wigglin (You can see more permutations of this idea in that Abzu video I linked above. They did basically the same thing with all those fish!)