Repository navigation
Animating Particles #1 ‐ RotationOverLifetime & ScaleOverLifetime
Back in the Getting Started page, we managed to add some randomness to our particles by setting various properties to be a table instead of a fixed number. This made the particles look less predictable and more natural!
...
However, there's a problem.
The moment they spawn, they retain the same color, speed, rotation, and other attributes throughout their whole lifetime. Because of that, our particles can still look quite unnatural! In fact, every single particle so far pops in and out of existence.
Particle Emitters, just like Unity's Shuriken Particle System, offer what are known as modules. Modules are a set of properties that, when enabled, allow us to further customize a Particle Emitter's behavior, including how particles are animated throughout their lifetime. This page will introduce two new modules:
RotationOverLifetimeScaleOverLifetime
RotationOverLifetime is a module that allows particles to change their angular velocity over their lifetime. By default, it's disabled. However, enabling it is quite straightforward:
local emitter = Palette:CreateParticleEmitter("gfx/particle.png")
emitter.RotationOverLifetime.Enabled = trueFrom there, the RotationOverLifetime module is enabled! On its own, just enabling it won't do anything as we need to first set up their keyframes.
If you've ever animated anything in your life, you likely already know what a keyframe is: the principles apply here!
In Palette, a keyframe is a point in a particle's lifetime that defines a specific value. A keyframe is represented as a table with these fields:
{
Time = 0,
Value = 0
}-
Time: A normalized number between 0 and 1, with 0 meaning the moment the particle was spawned and 1 meaning at the end of a particle's lifetime before it's removed. It can be set to other values too, like 0.5 being when the particle has reached half of its lifetime, and so on. -
Value: The value that is chosen once the specific timepoint defined inTimewas reached. In the case ofRotationOverLifetime, the value would represent the particle's angular velocity. By default, Palette interpolates between keyframes.
You can access the list of keyframes via emitter.RotationOverLifetime.Keys, which stores a table of keyframes. Below is an example where we assign it three different keyframes.
-- Inside `MC_POST_NEW_ROOM`
local spawnPos = Game():GetRoom():GetCenterPos()
local emitter = Palette:CreateParticleEmitter("gfx/particle.png", spawnPos)
emitter.StartScale = Vector(1.5, 1)
emitter.RotationOverLifetime.Enabled = true
emitter.RotationOverLifetime.Keys = {
{ Time = 0, Value = 0 },
{ Time = 0.5, Value = 10 },
{ Time = 1, Value = 0 }
}Warning
You must have the keyframes in Keys ordered by Time in ascending order. Having the keyframes be out of order will cause unexpected behavior.
❌BAD
emitter.RotationOverLifetime.Keys = {
{ Time = 0.5, Value = 10 },
{ Time = 0, Value = 0 },
{ Time = 1, Value = 0 }
}Notice how the first keyframe in the table has a time of 0.5, causing it to be out of order.
Note
There's no limit to how many keyframes you can have, as long as Keys is ordered properly. If Keys is empty, the module will fall back to a default value, which varies across modules.
Note
Assuming you've been using the image provided at the start of the tutorial, we assigned it a StartScale of Vector(1.5, 1) to stretch it out horizontally to illustrate the rotation since the image's a perfect circle. However, if you're using your own image, you're free to remove that line.
The above example will cause the particle's angular velocity at the very start to be 0. The velocity will gradually increase throughout the particle's lifetime until it reaches the halfway point, which then the angular velocity will be 10. From then, the angular velocity will decrease until the end of the particle's lifetime, where it returns to 0.
Here's a video of it in action:
2026-10-18.17-26-40.mp4
Notice how each particle initially starts with no angular velocity before gradually speeding up. The moment the particle reaches halfway of its lifetime, it begins to gradually come to a stop.
From our earlier example, you saw that the angular velocity for the particles gradually changed. This is because Palette is changing the velocity by smoothly interpolating it between each keyframe. This behavior can be changed through the Mode field in the module. By default, there are two modes:
-
"Blend": The default value, which causes the particular value to smoothly interpolate between keyframes. -
"Fixed": Disables smooth interpolation. Instead, upon reaching a timepoint, the value is immediately set to the keyframe's value.
Let's take our earlier code example and set Mode to "Fixed":
-- Inside `MC_POST_NEW_ROOM`
local spawnPos = Game():GetRoom():GetCenterPos()
local emitter = Palette:CreateParticleEmitter("gfx/particle.png", spawnPos)
emitter.StartScale = Vector(1.5, 1)
emitter.RotationOverLifetime.Enabled = true
emitter.RotationOverLifetime.Mode = "Fixed"
emitter.RotationOverLifetime.Keys = {
{ Time = 0, Value = 0 },
{ Time = 0.5, Value = 10 },
{ Time = 1, Value = 0 }
}2026-10-18.18-37-41.mp4
Notice how now instead of the angular velocity gradually changing all the time, its instant. When the particle first spawns, since the first keyframe at Time = 0 has a value of 0, there's no angular velocity. When the second keyframe is reached once the particle reaches half of its lifetime, its angular velocity is set to 10 immediately instead of having a smooth transition.
So far, we've managed to use RotationOverLifetime to have particles change their angular velocity in different ways throughout their lifetime. However, each particle consequently would have the exact same rotation animation. What if there was a way to still be able to add in randomness, so we can achieve effects such as having some particles rotate slowly while others rotate faster. Fortunately, this is where the CurveMode field comes in.
CurveMode dictates how keyframes are used (though not to be confused with Mode which only defines interpolation behavior) throughout the particle's lifetime. You can change the emitter's CurveMode via emitter.RotationOverLifetime.CurveMode. There are two values it can be:
-
"Single": The default value. Every particle uses the animation defined inKeys -
"TwoCurves": Defines two animations usingKeysMinandKeysMax. Each particle will then receive its own animation interpolated between these two curves.
Here is an example of TwoCurves:
-- Inside `MC_POST_NEW_ROOM`
local spawnPos = Game():GetRoom():GetCenterPos()
local emitter = Palette:CreateParticleEmitter("gfx/particle.png", spawnPos)
emitter.StartScale = Vector(1.5, 1)
emitter.RotationOverLifetime.Enabled = true
emitter.RotationOverLifetime.CurveMode = "TwoCurves"
emitter.RotationOverLifetime.KeysMin = {
{ Time = 0, Value = 0 },
{ Time = 0.5, Value = 2 },
{ Time = 1, Value = 0 }
}
emitter.RotationOverLifetime.KeysMax = {
{ Time = 0, Value = 0 },
{ Time = 0.5, Value = 12 },
{ Time = 1, Value = 0 }
}To explain how this works, when a particle spawns in, it gets its own interpolation factor between 0 and 1. KeysMin and KeysMax are independently evaluated at the particle's normalized lifetime, and the final value is an interpolation of the two results using its interpolation factor. Here is a video of the above snippet in action:
2026-10-18.19-05-09.mp4
Now the angular velocity of all particles accelerates to a random speed before decelerating after half of the particle's lifetime has passed.
Since both keyframes at time 0 start with a value of 0, all particles still start with no angular velocity. However, in both KeysMin and KeysMax, they have different values at Time = 0.5. The particle's random interpolation factor causes it to randomly have its angular velocity accelerate to a value between 2 and 12.
Note
For "TwoCurves", KeysMin and KeysMax do not need to have the same number of keyframes or keyframes with the same timestamp!
Now that we've extensively covered RotationOverLifetime, let's go over ScaleOverLifetime.
ScaleOverLifetime is a module that affects a particle's size throughout its lifetime. The value evaluated from the keyframes acts as a size multiplier to the emitter's StartScale property.
Just like RotationOverLifetime, it has the exact same properties and is initially disabled. Here's an example of setting it up:
-- Inside `MC_POST_NEW_ROOM`
local spawnPos = Game():GetRoom():GetCenterPos()
local emitter = Palette:CreateParticleEmitter("gfx/particle.png", spawnPos)
emitter.ScaleOverLifetime.Enabled = true
emitter.ScaleOverLifetime.Keys = {
{ Time = 0, Value = Vector(0, 0) },
{ Time = 0.5, Value = Vector(1, 1) },
{ Time = 1, Value = Vector(0, 0) }
}You'll immediately see how familiar this pattern is! It's set up just like RotationOverLifetime (and has the exact same properties!), with the only difference being that the values of keyframes are now Vectors.
Testing it in-game:
2026-10-18.19-37-37.mp4
You'll see that due to the keys we set up, all particles start off with a size of 0 (since it's set as Vector(0, 0)) before the particle gradually reaches its original size halfway through its lifetime, before gradually shrinking back into nothing right after.
Straightforward, huh?
Using everything we've learned so far throughout the tutorials, here is a cool spiral effect, utilizing the ScaleOverLifetime and RotationOverLifetime modules.
2026-10-18.19-55-27.mp4
local mod = RegisterMod("Palette Test", 1)
local Palette = include("palette_scripts.palette")
Palette:Init(mod)
mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function()
local position = Game():GetRoom():GetCenterPos()
local shards = Palette:CreateParticleEmitter("gfx/particle.png", position)
shards.MaxParticles = 180
shards.ParticleRate = 85
shards.Lifetime = { Min = 25, Max = 45 }
shards.StartSpeed = { Min = 1.5, Max = 4 }
shards.DirectionSpread = 180
shards.StartRotation = { Min = 0, Max = 360 }
shards.StartScale = {
Min = Vector(0.15, 0.45),
Max = Vector(0.25, 0.8)
}
shards.StartColor = {
Min = KColor(0.200, 0.180, 0.882, 0.85),
Max = KColor(0.863, 0.275, 0.373, 1)
}
shards.ScaleOverLifetime.Enabled = true
shards.ScaleOverLifetime.Keys = {
{ Time = 0, Value = Vector(0, 0) },
{ Time = 0.2, Value = Vector(1, 1) },
{ Time = 0.55, Value = Vector(1.2, 1.2) },
{ Time = 1, Value = Vector(0, 0) }
}
shards.RotationOverLifetime.Enabled = true
shards.RotationOverLifetime.CurveMode = "TwoCurves"
shards.RotationOverLifetime.KeysMin = {
{ Time = 0, Value = -2 },
{ Time = 0.5, Value = -12 },
{ Time = 1, Value = -3 }
}
shards.RotationOverLifetime.KeysMax = {
{ Time = 0, Value = 2 },
{ Time = 0.5, Value = 12 },
{ Time = 1, Value = 3 }
}
local glow = Palette:CreateParticleEmitter("gfx/particle.png", position)
glow.MaxParticles = 100
glow.ParticleRate = 50
glow.Lifetime = { Min = 18, Max = 38 }
glow.StartSpeed = { Min = 0.5, Max = 2 }
glow.DirectionSpread = 180
glow.StartScale = {
Min = Vector(0.4, 0.4),
Max = Vector(0.85, 0.85)
}
glow.StartColor = {
Min = KColor(0.859, 0.682, 0.420, 0.20),
Max = KColor(0.859, 0.682, 0.420, 0.45)
}
glow.ScaleOverLifetime.Enabled = true
glow.ScaleOverLifetime.Keys = {
{ Time = 0, Value = Vector(0, 0) },
{ Time = 0.3, Value = Vector(1, 1) },
{ Time = 0.65, Value = Vector(1.3, 1.3) },
{ Time = 1, Value = Vector(0, 0) }
}
end)- Palette API
- Particle Emitter API
- AlignToVelocity API
- ColorBySpeed API
- ColorOverLifetime API
- ForceOverLifetime API
- InheritVelocity API
- Keyframe API
- LimitVelocityOverLifetime API
- Noise API
- PaletteBurst API
- PaletteGradient API
- PaletteOverLifetime API
- RotationBySpeed API
- ScaleBySpeed API
- Shape API
- SpriteSheet API
- SubEmitterOptions API
- VelocityOverLifetime API