Skip to main content

Particle

Represents a particle that can be spawned and modified

Obtained by indexing the ParticleAPI

Exists as an object-oriented alternative to particles:addParticle()

For the examples on this page assume:

myParticle = particles["explosion"]

spawn()

Spawns this particle with the current properties

spawn()

Returns:

TypeDescription
ParticleSpawns the particle in the world

Example:

myParticle:spawn()

setPos()

Aliases: pos()

Sets this particle position

The position is given in world coordinates

setPos(pos)

Parameters:

NameTypeDescriptionDefault
posVector3Sets the position of the particle in the worldvec(0,0,0)

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

-- player position example
myParticle:setPos(player:getPos())
-- model part position example
myParticle:setPos(modelpart:partToWorldMatrix():apply())

getPos()

Gets this particle position

getPos()

Returns:

TypeDescription
Vector3Gets the position the particle is at

Example:

myParticle:getPos()

setColor()

Aliases: color()

Sets this particle's color, values must be between 0 and 1

Accepts an alpha value, but most particles do not support it

Default RGBA of 1

setColor(rgb)

Parameters:

NameTypeDescriptionDefault
rgbVector3The RGB color applied to the particlevec(1,1,1)

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:setColor(1, 0, 1)

getColor()

Gets this particle color

getColor()

Returns:

TypeDescription
Vector4Gets the RGBA color applied to the particle by setColor

Example:

myParticle:getColor()

setScale()

Aliases: scale(), setSize(), size()

Sets this particle scale

setScale(scale)

Parameters:

NameTypeDescriptionDefault
scaleNumberSets the scale of both axes of the particle1

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:setScale(2)

getScale()

Aliases: getSize()

Gets this particle scale

getScale()

Returns:

TypeDescription
NumberGets the scale of the particle

Example:

myParticle:getScale()

setVelocity()

Aliases: velocity()

Sets the velocity of this particle

The velocity is given in world coordinates

setVelocity(velocity)

Parameters:

NameTypeDescriptionDefault
velocityVector3-The default velocity of the particle

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:setVelocity(0, 5, 0)

getVelocity()

Gets the velocity of this particle

getVelocity()

Returns:

TypeDescription
Vector3Gets the velocity of the particle

Example:

myParticle:getVelocity()

setLifetime()

Aliases: lifetime()

Sets this particle lifetime, which is how many ticks this particle should stay in the world

setLifetime(lifetime)

Parameters:

NameTypeDescriptionDefault
lifetimeIntegerHow long the particle will stay in the world in ticksThe default lifetime of the particle

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:setLifetime(100)

getLifetime()

Gets this particle current lifetime

getLifetime()

Returns:

TypeDescription
IntegerGets how long the particle will stay in the world in ticks

Example:

myParticle:getLifetime()

setPower()

Aliases: power()

Multiplies the particle's velocity every time it's run

setPower(power)

Parameters:

NameTypeDescriptionDefault
powerNumber--

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:setPower(2)

getPower()

Gets the last number passed into setPower, but not the total power of the particle

caution

getPower doesn't get the particle's actual power, but the number last passed into setPower

getPower()

Returns:

TypeDescription
NumberGets the power of the particle

Example:

myParticle:getPower()

setGravity()

Aliases: gravity()

Sets the strength of the particle's gravity

setGravity(gravity)

Parameters:

NameTypeDescriptionDefault
gravityNumberSets the strength of the particle's gravity1

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:setGravity(5)

getGravity()

Gets this particle gravity

getGravity()

Returns:

TypeDescription
NumberGets the strength of the particle's gravity

Example:

myParticle:getGravity()

setPhysics()

Aliases: physics()

Sets if this particle has physics

setPhysics(physics)

Parameters:

NameTypeDescriptionDefault
physicsBooleanBoolean that turns physics on if true, and turns physics off if falsetrue

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:setPhysics(false)

hasPhysics()

Gets if this particle has physics

hasPhysics()

Returns:

TypeDescription
BooleanGets if this particle has physics

Example:

myParticle:hasPhysics()

remove()

Removes this particle from the world

remove()

Returns:

TypeDescription
ParticleReturns the particle for chaining

Example:

myParticle:remove()

isAlive()

Checks if this particle is not flagged for removal

isAlive()

Returns:

TypeDescription
BooleanReturns if the particle is alive

Example:

myParticle:isAlive()