Skip to main content
Version: Phaser v4.0.0

GravityWell

The Gravity Well Particle Processor applies a force on the particles to draw them towards, or repel them from, a single point.

The force applied is inversely proportional to the square of the distance from the particle to the point, in accordance with Newton's law of gravity.

This simulates the effect of gravity over large distances (as between planets, for example).

Constructor

new GravityWell([x], [y], [power], [epsilon], [gravity])

Parameters

nametypeoptionaldefaultdescription
xnumber | Phaser.Types.GameObjects.Particles.GravityWellConfigYes0The x coordinate of the Gravity Well, in world space.
ynumberYes0The y coordinate of the Gravity Well, in world space.
powernumberYes0The strength of the gravity force - larger numbers produce a stronger force.
epsilonnumberYes100The minimum distance for which the gravity force is calculated.
gravitynumberYes50The gravitational force of this Gravity Well.

Scope: static

Extends

Phaser.GameObjects.Particles.ParticleProcessor

Source: src/gameobjects/particles/GravityWell.js#L11
Since: 3.0.0

Inherited Members

From Phaser.GameObjects.Particles.ParticleProcessor:


Public Members

epsilon

epsilon: number

Description:

The minimum distance for which the gravity force is calculated, in pixels.

This acts as a lower bound on the distance used in the gravity calculation, preventing extreme or infinite forces when a particle passes very close to the well's position. Increase this value to soften the effect at close range.

Defaults to 100.

Source: src/gameobjects/particles/GravityWell.js#L132
Since: 3.0.0


gravity

gravity: number

Description:

The base gravitational force of this Gravity Well. This value acts as a scalar that is multiplied with power to determine the total force applied to particles. Increasing gravity amplifies the effect of power; setting it to zero will neutralise the well regardless of the power value.

Defaults to 50.

Source: src/gameobjects/particles/GravityWell.js#L186
Since: 3.0.0


power

power: number

Description:

The strength of the gravity force - larger numbers produce a stronger attractive force. Negative values reverse the effect, repelling particles away from the well instead.

Internally this value is scaled by gravity, so changing gravity will also affect the effective force even if power remains the same.

Defaults to 0.

Source: src/gameobjects/particles/GravityWell.js#L159
Since: 3.0.0


Inherited Methods

From Phaser.GameObjects.Particles.ParticleProcessor:


Public Methods

update

<instance> update(particle, delta, step)

Description:

Takes a Particle and updates its velocity based on the gravitational force exerted by this Gravity Well. The force is calculated using the squared distance between the particle and the well, clamped by epsilon to avoid extreme forces at very close range, then applied to the particle's horizontal and vertical velocity components.

Parameters:

nametypeoptionaldescription
particlePhaser.GameObjects.Particles.ParticleNoThe Particle to update.
deltanumberNoThe delta time in ms.
stepnumberNoThe delta value divided by 1000.

Overrides: Phaser.GameObjects.Particles.ParticleProcessor#update

Source: src/gameobjects/particles/GravityWell.js#L95
Since: 3.0.0