Velocity-aligned particles in Niagara

November 04, 2020
Velocity-aligned particles in Niagara

If you haven't been living under a rock you may have heard of a small twin-stick shooter game called Geometry Wars. Its lysergic artstyle captured many players back in the day to the extent some people bought Project Gotham Racing 2 just to play the aforementioned mini-game in the garage.

Geometry Wars

It was probably the first game I saw that made me realize that avalanches of particles can be really awesome and I wanted to replicate some of those effects in my game. Most notably: the alignment of the particles to their direction.

Unreal Engine 4 allows you to set the particle alignment both in Cascade and Niagara, usually under the rendering properties of the particle.

Unreal Engine Niagara System

Everything seems fine and dandy, until you watch the game through an orthographic camera, then you realize something really wrong is happening.

Particle alignment not working

Velocity alignment in orthographic projection simply never worked. In Cascade, particles seem to always face the world origin (0, 0, 0) while in Niagara they just freak out.

Previously, when Niagara was still in preview, I wrote a module to override the rotation of the particles. With just a bit of vector math particles would rotate according to their velocity when projected on the XZ plane.

Fortunately for us, Niagara now has many more features and I don't need a custom module any more. In the particle rendering options, setting the facing mode to "Custom facing vector" allows the user to define direction (or normal) the particles should always look. Adding the variable "Particles.SpriteFacing" under the "ParticleSpawn" section is enough to achieve the desired result.

Particle alignment facing attribute

The Particles face the camera correctly now, and with collision detection the effect really shows.