Static particles can look pretty boring. Particle modules allow certain particle properties to change over time, for example rotation or color. These modules are represented as functions, that can be applied per-emitter on every particle in every tick.
Looks simple doesn't it? But don't be deceived - they are much more powerful than you might initially think!
Let's say you wanted to make your particle's sizes pulse over time using a sine wave. Well, then you just need to pass a function that does exactly that into your emitter's modules!
However, writing functions like that for every single property you want to animate is boring and can get messy. You can still use them for more advanced cases, but for simple ones we will take a look at the
ModuleBuilder class is a utility class that allows us to construct
ModuleFunctions (as seen above) from specific parameters. Let's jump in and take a look at an example:
This can be read as: we're creating a new module builder that drives the size of a particle using the specified function, that takes the particle's lifetime as a factor.
Specifies the particle property to drive through the module function. Currently supported are
Specifies the value to drive the value by. This can either be a constant, a spline or a function that calculates a value from a factor and the particle as context.
Specifies the factor used to evaluate the driving value specified with
.by(). Currently supports
lifetime (in seconds),
relativeLifetime (from 0 to 1) and
size. By default, this uses the
Chains the module function to be applied relative to the initial value. Note that this is only supported for properties that have an initial value in the particle object, currently
size. The operation applied to the new and initial value is inferred from their types:
Vector: Both vectors are added.
number: Both numbers are multiplied.