Skip to main content
Version: Phaser v4.0.0

Body

A Dynamic Arcade Body. This body type can move, accelerate, collide with other bodies, and bounce off surfaces. It supports rectangular and circular collision shapes, and provides velocity, acceleration, drag (with optional damping mode), friction, gravity, bounce, and world bounds collision. Dynamic bodies are the most common physics body type, used for players, enemies, projectiles, and other moving game entities.

Its static counterpart is Phaser.Physics.Arcade.StaticBody.

Constructor

new Body(world, [gameObject])

Parameters

nametypeoptionaldescription
worldPhaser.Physics.Arcade.WorldNoThe Arcade Physics simulation this Body belongs to.
gameObjectPhaser.GameObjects.GameObjectYesThe Game Object this Body belongs to. As of Phaser 3.60 this is now optional.

Scope: static

Extends

Phaser.Physics.Arcade.Components.Collision

Source: src/physics/arcade/Body.js#L17
Since: 3.0.0

Public Members

acceleration

acceleration: Phaser.Math.Vector2

Description:

The Body's change in velocity, in pixels per second squared.

Source: src/physics/arcade/Body.js#L363
Since: 3.0.0


allowDrag

allowDrag: boolean

Description:

Whether this Body's velocity is affected by its drag.

Source: src/physics/arcade/Body.js#L372
Since: 3.0.0


allowGravity

allowGravity: boolean

Description:

Whether this Body's position is affected by gravity (local or world).

Source: src/physics/arcade/Body.js#L403
Since: 3.0.0


allowRotation

allowRotation: boolean

Description:

Whether this Body's rotation is affected by its angular acceleration and angular velocity.

Source: src/physics/arcade/Body.js#L221
Since: 3.0.0


angle

angle: number

Description:

The calculated angle of this Body's velocity vector, in radians, during the last step.

Source: src/physics/arcade/Body.js#L601
Since: 3.0.0


angularAcceleration

angularAcceleration: number

Description:

The Body's angular acceleration (change in angular velocity), in degrees per second squared.

Source: src/physics/arcade/Body.js#L558
Since: 3.0.0


angularDrag

angularDrag: number

Description:

Loss of angular velocity due to angular movement, in degrees per second.

Angular drag is applied only when angular acceleration is zero.

Source: src/physics/arcade/Body.js#L568
Since: 3.0.0


angularVelocity

angularVelocity: number

Description:

The rate of change of this Body's rotation, in degrees per second.

Source: src/physics/arcade/Body.js#L548
Since: 3.0.0


blocked

blocked: Phaser.Types.Physics.Arcade.ArcadeBodyCollision

Description:

Whether this Body is colliding with a Static Body, a tile, or the world boundary. In a collision with a Static Body, if this Body has zero velocity then embedded will be set instead.

Source: src/physics/arcade/Body.js#L807
Since: 3.0.0


bottom

bottom: number

Description:

The bottom edge of this Body.

Source: src/physics/arcade/Body.js#L2784
Since: 3.0.0


bounce

bounce: Phaser.Math.Vector2

Description:

Rebound following a collision, relative to 1.

Source: src/physics/arcade/Body.js#L426
Since: 3.0.0


center

center: Phaser.Math.Vector2

Description:

The center of the Body. The midpoint of its position (top-left corner) and its bottom-right corner.

Source: src/physics/arcade/Body.js#L323
Since: 3.0.0


checkCollision

checkCollision: Phaser.Types.Physics.Arcade.ArcadeBodyCollision

Description:

Whether this Body is checked for collisions and for which directions. You can set checkCollision.none = true to disable collision checks.

Source: src/physics/arcade/Body.js#L773
Since: 3.0.0


collideWorldBounds

collideWorldBounds: boolean

Description:

Whether this Body interacts with the world boundary.

Source: src/physics/arcade/Body.js#L763
Since: 3.0.0


collisionCategory

collisionCategory: number

Description:

The Arcade Physics Body Collision Category.

This can be set to any valid collision bitfield value.

See the setCollisionCategory method for more details.

Source: src/physics/arcade/Body.js#L842
Since: 3.70.0


collisionMask

collisionMask: number

Description:

The Arcade Physics Body Collision Mask.

See the setCollidesWith method for more details.

Source: src/physics/arcade/Body.js#L855
Since: 3.70.0


customBoundsRectangle

customBoundsRectangle: Phaser.Geom.Rectangle

Description:

The rectangle used for world boundary collisions.

By default it is set to the world boundary rectangle. Or, if this Body was created by a Physics Group, then whatever rectangle that Group defined.

You can also change it by using the Body.setBoundsRectangle method.

Source: src/physics/arcade/Body.js#L446
Since: 3.20


customSeparateX

customSeparateX: boolean

Description:

A flag disabling the default horizontal separation of colliding bodies. Pass your own collideCallback to the collider.

Source: src/physics/arcade/Body.js#L701
Since: 3.0.0


customSeparateY

customSeparateY: boolean

Description:

A flag disabling the default vertical separation of colliding bodies. Pass your own collideCallback to the collider.

Source: src/physics/arcade/Body.js#L712
Since: 3.0.0


debugBodyColor

debugBodyColor: number

Description:

The color of this Body on the debug display.

Source: src/physics/arcade/Body.js#L139
Since: 3.0.0


debugShowBody

debugShowBody: boolean

Description:

Whether the Body is drawn to the debug display.

Source: src/physics/arcade/Body.js#L121
Since: 3.0.0


debugShowVelocity

debugShowVelocity: boolean

Description:

Whether the Body's velocity is drawn to the debug display.

Source: src/physics/arcade/Body.js#L130
Since: 3.0.0


deltaMax

deltaMax: Phaser.Math.Vector2

Description:

The Body's absolute maximum change in position, in pixels per step.

Source: src/physics/arcade/Body.js#L354
Since: 3.0.0


directControl

directControl: boolean

Description:

Is this Body under direct control, outside of the physics engine? For example, are you trying to move it via a Tween? Or have it follow a path? If so then you can enable this boolean so that the Body will calculate its velocity based purely on its change in position each frame. This allows you to then tween the position and still have it collide with other objects. However, setting the velocity will have no impact on this Body while this is set.

Source: src/physics/arcade/Body.js#L940
Since: 3.70.0


drag

drag: Phaser.Math.Vector2

Description:

When useDamping is false (the default), this is absolute loss of velocity due to movement, in pixels per second squared.

When useDamping is true, this is a damping multiplier between 0 and 1.

A value of 0 means the Body stops instantly. A value of 0.01 mean the Body keeps 1% of its velocity per second, losing 99%. A value of 0.1 means the Body keeps 10% of its velocity per second, losing 90%. A value of 1 means the Body loses no velocity. You can use very small values (e.g., 0.001) to stop the Body quickly.

The x and y components are applied separately.

Drag is applied only when acceleration is zero.

Source: src/physics/arcade/Body.js#L382
Since: 3.0.0


embedded

embedded: boolean

Description:

Whether this Body is overlapped with another and both are not moving, on at least one axis.

Source: src/physics/arcade/Body.js#L753
Since: 3.0.0


enable

enable: boolean

Description:

Whether this Body is updated by the physics simulation.

Source: src/physics/arcade/Body.js#L148
Since: 3.0.0


facing

facing: number

Description:

The direction of the Body's velocity, as calculated during the last step. This is a numeric constant value (FACING_UP, FACING_DOWN, FACING_LEFT, FACING_RIGHT). If the Body is moving on both axes, this describes motion on the vertical axis only.

Source: src/physics/arcade/Body.js#L621
Since: 3.0.0


friction

friction: Phaser.Math.Vector2

Description:

If this Body is immovable and in motion, friction is the proportion of this Body's motion received by the riding Body on each axis, relative to 1. The horizontal component (x) is applied only when two colliding Bodies are separated vertically. The vertical component (y) is applied only when two colliding Bodies are separated horizontally. The default value (1, 0) moves the riding Body horizontally in equal proportion to this Body and vertically not at all.

Source: src/physics/arcade/Body.js#L518
Since: 3.0.0


gameObject

gameObject: Phaser.GameObjects.GameObject

Description:

The Game Object this Body belongs to.

As of Phaser 3.60 this is now optional and can be undefined.

Source: src/physics/arcade/Body.js#L83
Since: 3.0.0


gravity

gravity: Phaser.Math.Vector2

Description:

Acceleration due to gravity (specific to this Body), in pixels per second squared. Total gravity is the sum of this vector and the simulation's gravity.

Source: src/physics/arcade/Body.js#L415
Since: 3.0.0


halfHeight

halfHeight: number

Description:

Half the Body's height, in pixels.

Source: src/physics/arcade/Body.js#L314
Since: 3.0.0


halfWidth

halfWidth: number

Description:

Half the Body's width, in pixels.

Source: src/physics/arcade/Body.js#L305
Since: 3.0.0


height

height: number

Description:

The height of the Body, in pixels. If the Body is circular, this is also the diameter. If you wish to change the height use the Body.setSize method.

Source: src/physics/arcade/Body.js#L264
Since: 3.0.0


immovable

immovable: boolean

Description:

Whether this Body can be moved by collisions with another Body.

Source: src/physics/arcade/Body.js#L637
Since: 3.0.0


isBody

isBody: boolean

Description:

A quick-test flag that signifies this is a Body, used in the World collision handler.

Source: src/physics/arcade/Body.js#L94
Since: 3.60.0


isCircle

isCircle: boolean

Description:

Whether this Body is circular (true) or rectangular (false).

Source: src/physics/arcade/Body.js#L158
Since: 3.0.0


left

left: number

Description:

The left edge of the Body. Identical to x.

Source: src/physics/arcade/Body.js#L2733
Since: 3.0.0


mass

mass: number

Description:

The Body's inertia, relative to a default unit (1). With bounce, this affects the exchange of momentum (velocities) during collisions.

Source: src/physics/arcade/Body.js#L590
Since: 3.0.0


maxAngular

maxAngular: number

Description:

The Body's maximum angular velocity, in degrees per second.

Source: src/physics/arcade/Body.js#L580
Since: 3.0.0


maxSpeed

maxSpeed: number

Description:

The maximum speed this Body is allowed to reach, in pixels per second.

If not negative it limits the scalar value of speed.

Any negative value means no maximum is being applied (the default).

Source: src/physics/arcade/Body.js#L504
Since: 3.16.0


maxVelocity

maxVelocity: Phaser.Math.Vector2

Description:

The absolute maximum velocity of this body, in pixels per second. The horizontal and vertical components are applied separately.

Source: src/physics/arcade/Body.js#L494
Since: 3.0.0


moves

moves: boolean

Description:

Whether the Body's position and rotation are affected by its velocity, acceleration, drag, and gravity.

Source: src/physics/arcade/Body.js#L691
Since: 3.0.0


newVelocity

newVelocity: Phaser.Math.Vector2

Description:

The Body's change in position (due to velocity) at the last step, in pixels.

The size of this value depends on the simulation's step rate.

Source: src/physics/arcade/Body.js#L342
Since: 3.0.0


offset

offset: Phaser.Math.Vector2

Description:

The offset of this Body's position from its Game Object's position, in source pixels.

Source: src/physics/arcade/Body.js#L181
Since: 3.0.0


onCollide

onCollide: boolean

Description:

Whether the simulation emits a collide event when this Body collides with another.

Source: src/physics/arcade/Body.js#L472
Since: 3.0.0


onOverlap

onOverlap: boolean

Description:

Whether the simulation emits an overlap event when this Body overlaps with another.

Source: src/physics/arcade/Body.js#L483
Since: 3.0.0


onWorldBounds

onWorldBounds: boolean

Description:

Whether the simulation emits a worldbounds event when this Body collides with the world boundary (and collideWorldBounds is also true).

Source: src/physics/arcade/Body.js#L460
Since: 3.0.0


overlapR

overlapR: number

Description:

The amount of overlap (before separation), if this Body is circular and colliding with another circular body.

Source: src/physics/arcade/Body.js#L743
Since: 3.0.0


overlapX

overlapX: number

Description:

The amount of horizontal overlap (before separation), if this Body is colliding with another.

Source: src/physics/arcade/Body.js#L723
Since: 3.0.0


overlapY

overlapY: number

Description:

The amount of vertical overlap (before separation), if this Body is colliding with another.

Source: src/physics/arcade/Body.js#L733
Since: 3.0.0


physicsType

physicsType: number

Description:

The Body's physics type (dynamic or static).

Source: src/physics/arcade/Body.js#L831
Since: 3.0.0


position

position: Phaser.Math.Vector2

Description:

The position of this Body within the simulation.

Source: src/physics/arcade/Body.js#L191
Since: 3.0.0


preRotation

preRotation: number

Description:

The Body rotation, in degrees, during the previous step.

Source: src/physics/arcade/Body.js#L242
Since: 3.0.0


prev

prev: Phaser.Math.Vector2

Description:

The position of this Body during the previous step.

Source: src/physics/arcade/Body.js#L203
Since: 3.0.0


prevFrame

prevFrame: Phaser.Math.Vector2

Description:

The position of this Body during the previous frame.

Source: src/physics/arcade/Body.js#L212
Since: 3.20.0


pushable

pushable: boolean

Description:

Sets if this Body can be pushed by another Body.

A body that cannot be pushed will reflect back all of the velocity it is given to the colliding body. If that body is also not pushable, then the separation will be split between them evenly.

If you want your body to never move or separate at all, see the setImmovable method.

By default, Dynamic Bodies are always pushable.

Source: src/physics/arcade/Body.js#L647
Since: 3.50.0


radius

radius: number

Description:

If this Body is circular, this is the unscaled radius of the Body, as set by setCircle(), in source pixels. The true radius is equal to halfWidth.

Source: src/physics/arcade/Body.js#L169
Since: 3.0.0


right: number

Description:

The right edge of the Body.

Source: src/physics/arcade/Body.js#L2750
Since: 3.0.0


rotation

rotation: number

Description:

This body's rotation, in degrees, based on its angular acceleration and angular velocity. The Body's rotation controls the angle of its Game Object. It doesn't rotate the Body's own geometry, which is always an axis-aligned rectangle or a circle.

Source: src/physics/arcade/Body.js#L231
Since: 3.0.0


slideFactor

slideFactor: Phaser.Math.Vector2

Description:

The Slide Factor of this Body.

The Slide Factor controls how much velocity is preserved when this Body is pushed by another Body.

The default value is 1, which means that it will take on all velocity given in the push. You can adjust this value to control how much velocity is retained by this Body when the push ends.

A value of 0, for example, will allow this Body to be pushed but then remain completely still after the push ends, such as you see in a game like Sokoban.

Or you can set a mid-point, such as 0.25 which will allow it to keep 25% of the original velocity when the push ends. You can combine this with the setDrag() method to create deceleration.

Source: src/physics/arcade/Body.js#L666
Since: 3.70.0


sourceHeight

sourceHeight: number

Description:

The unscaled height of the Body, in source pixels, as set by setSize(). The default is the height of the Body's Game Object's texture frame.

Source: src/physics/arcade/Body.js#L288
Since: 3.0.0


sourceWidth

sourceWidth: number

Description:

The unscaled width of the Body, in source pixels, as set by setSize(). The default is the width of the Body's Game Object's texture frame.

Source: src/physics/arcade/Body.js#L277
Since: 3.0.0


speed

speed: number

Description:

The calculated magnitude of the Body's velocity, in pixels per second, during the last step.

Source: src/physics/arcade/Body.js#L611
Since: 3.0.0


syncBounds

syncBounds: boolean

Description:

Whether to automatically synchronize this Body's dimensions to the dimensions of its Game Object's visual bounds.

Source: src/physics/arcade/Body.js#L820
Since: 3.0.0


top

top: number

Description:

The top edge of the Body. Identical to y.

Source: src/physics/arcade/Body.js#L2767
Since: 3.0.0


touching

touching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision

Description:

Whether this Body is colliding with a Body or Static Body and in which direction. In a collision where both bodies have zero velocity, embedded will be set instead.

Source: src/physics/arcade/Body.js#L783
Since: 3.0.0


transform

transform: object

Description:

Transformations applied to this Body.

Source: src/physics/arcade/Body.js#L104
Since: 3.4.0


useDamping

useDamping: boolean

Description:

If this Body is using drag for deceleration this property controls how the drag is applied. If set to true drag will use a damping effect rather than a linear approach. If you are creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in the game Asteroids) then you will get a far smoother and more visually correct deceleration by using damping, avoiding the axis-drift that is prone with linear deceleration.

If you enable this property then you should use far smaller drag values than with linear, as they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow deceleration.

Source: src/physics/arcade/Body.js#L530
Since: 3.10.0


velocity

velocity: Phaser.Math.Vector2

Description:

The Body's velocity, in pixels per second.

Source: src/physics/arcade/Body.js#L333
Since: 3.0.0


wasTouching

wasTouching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision

Description:

This Body's touching value during the previous step.

Source: src/physics/arcade/Body.js#L796
Since: 3.0.0


width

width: number

Description:

The width of the Body, in pixels. If the Body is circular, this is also the diameter. If you wish to change the width use the Body.setSize method.

Source: src/physics/arcade/Body.js#L251
Since: 3.0.0


world

world: Phaser.Physics.Arcade.World

Description:

The Arcade Physics simulation this Body belongs to.

Source: src/physics/arcade/Body.js#L74
Since: 3.0.0


worldBounce

worldBounce: Phaser.Math.Vector2

Description:

Rebound following a collision with the world boundary, relative to 1. If null, bounce is used instead.

Source: src/physics/arcade/Body.js#L435
Since: 3.0.0


x

x: number

Description:

The Body's horizontal position (left edge).

Source: src/physics/arcade/Body.js#L2691
Since: 3.0.0


y

y: number

Description:

The Body's vertical position (top edge).

Source: src/physics/arcade/Body.js#L2712
Since: 3.0.0


Inherited Methods

From Phaser.Physics.Arcade.Components.Collision:


Public Methods

checkWorldBounds

<instance> checkWorldBounds()

Description:

Checks for collisions between this Body and the world boundary and separates them.

Returns: boolean - True if this Body is colliding with the world boundary.

Source: src/physics/arcade/Body.js#L1333
Since: 3.0.0


deltaAbsX

<instance> deltaAbsX()

Description:

The absolute (non-negative) change in this Body's horizontal position from the previous step.

Returns: number - The absolute change in horizontal position since the last step, in pixels.

Source: src/physics/arcade/Body.js#L1736
Since: 3.0.0


deltaAbsY

<instance> deltaAbsY()

Description:

The absolute (non-negative) change in this Body's vertical position from the previous step.

Returns: number - The absolute change in vertical position since the last step, in pixels.

Source: src/physics/arcade/Body.js#L1749
Since: 3.0.0


deltaX

<instance> deltaX()

Description:

The change in this Body's horizontal position from the previous step. This value is set during the Body's update phase.

As a Body can update multiple times per step this may not hold the final delta value for the Body. In this case, please see the deltaXFinal method.

Returns: number - The change in horizontal position since the last step, in pixels.

Source: src/physics/arcade/Body.js#L1762
Since: 3.0.0


deltaXFinal

<instance> deltaXFinal()

Description:

The change in this Body's horizontal position from the previous game update.

This value is set during the postUpdate phase and takes into account the deltaMax and final position of the Body.

Because this value is not calculated until postUpdate, you must listen for it during a Scene POST_UPDATE or RENDER event, and not in update, as it will not be calculated by that point. If you do use these values in update they will represent the delta from the previous game frame.

Returns: number - The final delta x value.

Source: src/physics/arcade/Body.js#L1796
Since: 3.22.0


deltaY

<instance> deltaY()

Description:

The change in this Body's vertical position from the previous step. This value is set during the Body's update phase.

As a Body can update multiple times per step this may not hold the final delta value for the Body. In this case, please see the deltaYFinal method.

Returns: number - The change in vertical position since the last step, in pixels.

Source: src/physics/arcade/Body.js#L1779
Since: 3.0.0


deltaYFinal

<instance> deltaYFinal()

Description:

The change in this Body's vertical position from the previous game update.

This value is set during the postUpdate phase and takes into account the deltaMax and final position of the Body.

Because this value is not calculated until postUpdate, you must listen for it during a Scene POST_UPDATE or RENDER event, and not in update, as it will not be calculated by that point. If you do use these values in update they will represent the delta from the previous game frame.

Returns: number - The final delta y value.

Source: src/physics/arcade/Body.js#L1817
Since: 3.22.0


deltaZ

<instance> deltaZ()

Description:

The change in this Body's rotation from the previous step, in degrees.

Returns: number - The change in rotation since the last step, in degrees.

Source: src/physics/arcade/Body.js#L1838
Since: 3.0.0


destroy

<instance> destroy()

Description:

Disables this Body and marks it for deletion by the simulation.

Source: src/physics/arcade/Body.js#L1851
Since: 3.0.0


drawDebug

<instance> drawDebug(graphic)

Description:

Draws this Body and its velocity, if enabled.

Parameters:

nametypeoptionaldescription
graphicPhaser.GameObjects.GraphicsNoThe Graphics object to draw on.

Source: src/physics/arcade/Body.js#L1867
Since: 3.0.0


getBounds

<instance> getBounds(obj)

Description:

Copies the coordinates of this Body's edges into an object.

Parameters:

nametypeoptionaldescription
objPhaser.Types.Physics.Arcade.ArcadeBodyBoundsNoAn object to copy the values into.

Returns: Phaser.Types.Physics.Arcade.ArcadeBodyBounds - - An object with {x, y, right, bottom}.

Source: src/physics/arcade/Body.js#L1644
Since: 3.0.0


hitTest

<instance> hitTest(x, y)

Description:

Tests if the coordinates are within this Body.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal coordinate.
ynumberNoThe vertical coordinate.

Returns: boolean - True if (x, y) is within this Body.

Source: src/physics/arcade/Body.js#L1664
Since: 3.0.0


onCeiling

<instance> onCeiling()

Description:

Whether this Body is touching a tile or the world boundary while moving up.

Returns: boolean - True if touching.

Source: src/physics/arcade/Body.js#L1708
Since: 3.0.0


onFloor

<instance> onFloor()

Description:

Whether this Body is touching a tile or the world boundary while moving down.

Returns: boolean - True if touching.

Source: src/physics/arcade/Body.js#L1694
Since: 3.0.0


onWall

<instance> onWall()

Description:

Whether this Body is touching a tile or the world boundary while moving left or right.

Returns: boolean - True if touching.

Source: src/physics/arcade/Body.js#L1722
Since: 3.0.0


postUpdate

<instance> postUpdate()

Description:

Feeds the Body results back into the parent Game Object.

This method is called every game frame, regardless if the world steps or not.

Source: src/physics/arcade/Body.js#L1233
Since: 3.0.0


preUpdate

<instance> preUpdate(willStep, delta)

Description:

Syncs the Body's position with the parent Game Object.

This method is called every game frame, regardless if the world steps or not.

Parameters:

nametypeoptionaldescription
willStepbooleanNoWill this Body run an update as well?
deltanumberNoThe delta time, in seconds, elapsed since the last frame.

Source: src/physics/arcade/Body.js#L1116
Since: 3.17.0


processX

<instance> processX(x, [vx], [left], [right])

Description:

This is an internal handler, called by the ProcessX function as part of the collision step. You should almost never call this directly.

Parameters:

nametypeoptionaldescription
xnumberNoThe amount to add to the Body position.
vxnumberYesThe amount to add to the Body velocity.
leftbooleanYesSet the blocked.left value?
rightbooleanYesSet the blocked.right value?

Source: src/physics/arcade/Body.js#L2615
Since: 3.50.0


processY

<instance> processY(y, [vy], [up], [down])

Description:

This is an internal handler, called by the ProcessY function as part of the collision step. You should almost never call this directly.

Parameters:

nametypeoptionaldescription
ynumberNoThe amount to add to the Body position.
vynumberYesThe amount to add to the Body velocity.
upbooleanYesSet the blocked.up value?
downbooleanYesSet the blocked.down value?

Source: src/physics/arcade/Body.js#L2653
Since: 3.50.0


reset

<instance> reset(x, y)

Description:

Sets this Body's parent Game Object to the given coordinates and resets this Body at the new coordinates. If the Body had any velocity or acceleration it is lost as a result of calling this.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal position to place the Game Object.
ynumberNoThe vertical position to place the Game Object.

Source: src/physics/arcade/Body.js#L1571
Since: 3.0.0


resetFlags

<instance> resetFlags([clear])

Description:

Prepares the Body for a physics step by resetting the wasTouching, touching and blocked states.

This method is only called if the physics world is going to run a step this frame.

Parameters:

nametypeoptionaldefaultdescription
clearbooleanYesfalseSet the wasTouching values to their defaults.

Source: src/physics/arcade/Body.js#L1071
Since: 3.18.0


setAcceleration

<instance> setAcceleration(x, [y])

Description:

Sets the Body's acceleration.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal component, in pixels per second squared.
ynumberYes"x"The vertical component, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2216
Since: 3.0.0


setAccelerationX

<instance> setAccelerationX(value)

Description:

Sets the Body's horizontal acceleration.

Parameters:

nametypeoptionaldescription
valuenumberNoThe acceleration, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2234
Since: 3.0.0


setAccelerationY

<instance> setAccelerationY(value)

Description:

Sets the Body's vertical acceleration.

Parameters:

nametypeoptionaldescription
valuenumberNoThe acceleration, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2251
Since: 3.0.0


setAllowDrag

<instance> setAllowDrag([value])

Description:

Enables or disables drag.

Parameters:

nametypeoptionaldefaultdescription
valuebooleanYestruetrue to allow drag on this body, or false to disable it.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2268
Since: 3.9.0


setAllowGravity

<instance> setAllowGravity([value])

Description:

Enables or disables gravity's effect on this Body.

Parameters:

nametypeoptionaldefaultdescription
valuebooleanYestruetrue to allow gravity on this body, or false to disable it.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2288
Since: 3.9.0


setAllowRotation

<instance> setAllowRotation([value])

Description:

Enables or disables rotation.

Parameters:

nametypeoptionaldefaultdescription
valuebooleanYestruetrue to allow rotation on this body, or false to disable it.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2308
Since: 3.9.0


setAngularAcceleration

<instance> setAngularAcceleration(value)

Description:

Sets the Body's angular acceleration.

Parameters:

nametypeoptionaldescription
valuenumberNoThe acceleration, in degrees per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2526
Since: 3.0.0


setAngularDrag

<instance> setAngularDrag(value)

Description:

Sets the Body's angular drag.

Parameters:

nametypeoptionaldescription
valuenumberNoThe drag, in degrees per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2543
Since: 3.0.0


setAngularVelocity

<instance> setAngularVelocity(value)

Description:

Sets the Body's angular velocity.

Parameters:

nametypeoptionaldescription
valuenumberNoThe velocity, in degrees per second.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2509
Since: 3.0.0


setBounce

<instance> setBounce(x, [y])

Description:

Sets the Body's bounce.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal bounce, relative to 1.
ynumberYes"x"The vertical bounce, relative to 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2164
Since: 3.0.0


setBounceX

<instance> setBounceX(value)

Description:

Sets the Body's horizontal bounce.

Parameters:

nametypeoptionaldescription
valuenumberNoThe bounce, relative to 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2182
Since: 3.0.0


setBounceY

<instance> setBounceY(value)

Description:

Sets the Body's vertical bounce.

Parameters:

nametypeoptionaldescription
valuenumberNoThe bounce, relative to 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2199
Since: 3.0.0


setBoundsRectangle

<instance> setBoundsRectangle([bounds])

Description:

Sets a custom collision boundary rectangle. Use if you want to have a custom boundary instead of the world boundaries.

Parameters:

nametypeoptionaldescription
boundsPhaser.Geom.RectangleYesThe new boundary rectangle. Pass null to use the World bounds.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1315
Since: 3.20


setCircle

<instance> setCircle(radius, [offsetX], [offsetY])

Description:

Sizes and positions this Body, as a circle.

Parameters:

nametypeoptionaldescription
radiusnumberNoThe radius of the Body, in source pixels.
offsetXnumberYesThe horizontal offset of the Body from its Game Object, in source pixels.
offsetYnumberYesThe vertical offset of the Body from its Game Object, in source pixels.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1528
Since: 3.0.0


setCollideWorldBounds

<instance> setCollideWorldBounds([value], [bounceX], [bounceY], [onWorldBounds])

Description:

Sets whether this Body collides with the world boundary.

Optionally also sets the World Bounce and onWorldBounds values.

Parameters:

nametypeoptionaldefaultdescription
valuebooleanYestruetrue if the Body should collide with the world bounds, otherwise false.
bounceXnumberYesIf given this replaces the Body's worldBounce.x value.
bounceYnumberYesIf given this replaces the Body's worldBounce.y value.
onWorldBoundsbooleanYesIf given this replaces the Body's onWorldBounds value.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1959
Since: 3.0.0


setDamping

<instance> setDamping(value)

Description:

If this Body is using drag for deceleration this property controls how the drag is applied. If set to true drag will use a damping effect rather than a linear approach. If you are creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in the game Asteroids) then you will get a far smoother and more visually correct deceleration by using damping, avoiding the axis-drift that is prone with linear deceleration.

If you enable this property then you should use far smaller drag values than with linear, as they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately.

Parameters:

nametypeoptionaldescription
valuebooleanNotrue to use damping, or false to use drag.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2346
Since: 3.50.0


setDirectControl

<instance> setDirectControl([value])

Description:

Sets whether this Body should calculate its velocity based on its change in position every frame. The default, which is to not do this, means that you make this Body move by setting the velocity directly. However, if you are trying to move this Body via a Tween, or have it follow a Path, then you should enable this instead. This will allow it to still collide with other bodies, something that isn't possible if you're just changing its position directly.

Parameters:

nametypeoptionaldefaultdescription
valuebooleanYestruetrue if the Body calculate velocity based on changes in position, otherwise false.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1935
Since: 3.70.0


setDrag

<instance> setDrag(x, [y])

Description:

Sets the Body's drag.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal component, in pixels per second squared.
ynumberYes"x"The vertical component, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2328
Since: 3.0.0


setDragX

<instance> setDragX(value)

Description:

Sets the Body's horizontal drag.

Parameters:

nametypeoptionaldescription
valuenumberNoThe drag, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2371
Since: 3.0.0


setDragY

<instance> setDragY(value)

Description:

Sets the Body's vertical drag.

Parameters:

nametypeoptionaldescription
valuenumberNoThe drag, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2388
Since: 3.0.0


setEnable

<instance> setEnable([value])

Description:

Sets the Body's enable property.

Parameters:

nametypeoptionaldefaultdescription
valuebooleanYestrueThe value to assign to enable.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2596
Since: 3.15.0


setFriction

<instance> setFriction(x, [y])

Description:

Sets the Body's friction.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal component, relative to 1.
ynumberYes"x"The vertical component, relative to 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2457
Since: 3.0.0


setFrictionX

<instance> setFrictionX(value)

Description:

Sets the Body's horizontal friction.

Parameters:

nametypeoptionaldescription
valuenumberNoThe friction value, relative to 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2475
Since: 3.0.0


setFrictionY

<instance> setFrictionY(value)

Description:

Sets the Body's vertical friction.

Parameters:

nametypeoptionaldescription
valuenumberNoThe friction value, relative to 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2492
Since: 3.0.0


setGameObject

<instance> setGameObject(gameObject, [enable])

Description:

Assign this Body to a new Game Object.

Removes this body from the Physics World, assigns to the new Game Object, calls setSize and then adds this body back into the World again, setting it enabled, unless the enable argument is set to false.

If this body already has a Game Object, then it will remove itself from that Game Object first.

If the given gameObject doesn't have a body property, it is created and this Body is assigned to it.

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object to assign this Body to.
enablebooleanYestrueAutomatically enable this Body for physics.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1414
Since: 3.60.0


setGravity

<instance> setGravity(x, [y])

Description:

Sets the Body's gravity.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal component, in pixels per second squared.
ynumberYes"x"The vertical component, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2405
Since: 3.0.0


setGravityX

<instance> setGravityX(value)

Description:

Sets the Body's horizontal gravity.

Parameters:

nametypeoptionaldescription
valuenumberNoThe gravity, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2423
Since: 3.0.0


setGravityY

<instance> setGravityY(value)

Description:

Sets the Body's vertical gravity.

Parameters:

nametypeoptionaldescription
valuenumberNoThe gravity, in pixels per second squared.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2440
Since: 3.0.0


setImmovable

<instance> setImmovable([value])

Description:

Sets the Body's immovable property.

Parameters:

nametypeoptionaldefaultdescription
valuebooleanYestrueThe value to assign to immovable.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2577
Since: 3.0.0


setMass

<instance> setMass(value)

Description:

Sets the Body's mass.

Parameters:

nametypeoptionaldescription
valuenumberNoThe mass value, relative to 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2560
Since: 3.0.0


setMaxSpeed

<instance> setMaxSpeed(value)

Description:

Sets the maximum speed the Body can move.

Parameters:

nametypeoptionaldescription
valuenumberNoThe maximum speed value, in pixels per second. Set to a negative value to disable.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2114
Since: 3.16.0


setMaxVelocity

<instance> setMaxVelocity(x, [y])

Description:

Sets the Body's maximum velocity.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal velocity, in pixels per second.
ynumberYes"x"The vertical velocity, in pixels per second.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2062
Since: 3.10.0


setMaxVelocityX

<instance> setMaxVelocityX(value)

Description:

Sets the Body's maximum horizontal velocity.

Parameters:

nametypeoptionaldescription
valuenumberNoThe maximum horizontal velocity, in pixels per second.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2080
Since: 3.50.0


setMaxVelocityY

<instance> setMaxVelocityY(value)

Description:

Sets the Body's maximum vertical velocity.

Parameters:

nametypeoptionaldescription
valuenumberNoThe maximum vertical velocity, in pixels per second.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2097
Since: 3.50.0


setOffset

<instance> setOffset(x, [y])

Description:

Sets the offset of the Body's position from its Game Object's position. The Body's position isn't changed until the next preUpdate.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal offset, in source pixels.
ynumberYes"x"The vertical offset, in source pixels.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1393
Since: 3.0.0


setSize

<instance> setSize([width], [height], [center])

Description:

Sizes and positions this Body, as a rectangle. Modifies the Body offset if center is true (the default). Resets the width and height to match current frame, if no width and height provided and a frame is found.

Parameters:

nametypeoptionaldefaultdescription
widthnumberYesThe width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width.
heightnumberYesThe height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height.
centerbooleanYestrueModify the Body's offset, placing the Body's center on its Game Object's center. Only works if the Game Object has the getCenter method.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1470
Since: 3.0.0


setSlideFactor

<instance> setSlideFactor(x, [y])

Description:

Sets the Slide Factor of this Body.

The Slide Factor controls how much velocity is preserved when this Body is pushed by another Body.

The default value is 1, which means that it will take on all velocity given in the push. You can adjust this value to control how much velocity is retained by this Body when the push ends.

A value of 0, for example, will allow this Body to be pushed but then remain completely still after the push ends, such as you see in a game like Sokoban.

Or you can set a mid-point, such as 0.25 which will allow it to keep 25% of the original velocity when the push ends. You can combine this with the setDrag() method to create deceleration.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal slide factor. A value between 0 and 1.
ynumberYes"x"The vertical slide factor. A value between 0 and 1.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2131
Since: 3.70.0


setVelocity

<instance> setVelocity(x, [y])

Description:

Sets the Body's velocity.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal velocity, in pixels per second.
ynumberYes"x"The vertical velocity, in pixels per second.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2009
Since: 3.0.0


setVelocityX

<instance> setVelocityX(value)

Description:

Sets the Body's horizontal velocity.

Parameters:

nametypeoptionaldescription
valuenumberNoThe velocity, in pixels per second.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2032
Since: 3.0.0


setVelocityY

<instance> setVelocityY(value)

Description:

Sets the Body's vertical velocity.

Parameters:

nametypeoptionaldescription
valuenumberNoThe velocity, in pixels per second.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L2047
Since: 3.0.0


stop

<instance> stop()

Description:

Sets acceleration, velocity, and speed to zero.

Returns: Phaser.Physics.Arcade.Body - This Body object.

Source: src/physics/arcade/Body.js#L1625
Since: 3.0.0


update

<instance> update(delta)

Description:

Performs a single physics step and updates the body velocity, angle, speed and other properties.

This method can be called multiple times per game frame, depending on the physics step rate.

The results are synced back to the Game Object in postUpdate.

Parameters:

nametypeoptionaldescription
deltanumberNoThe delta time, in seconds, elapsed since the last frame.

Fires: Phaser.Physics.Arcade.Events#event:WORLD_BOUNDS

Source: src/physics/arcade/Body.js#L1159
Since: 3.0.0


updateBounds

<instance> updateBounds()

Description:

Updates the Body's transform, width, height, and center from its Game Object. The Body's position isn't changed.

Source: src/physics/arcade/Body.js#L965
Since: 3.0.0


updateCenter

<instance> updateCenter()

Description:

Updates the Body's center from its position, width, and height.

Source: src/physics/arcade/Body.js#L1036
Since: 3.0.0


updateFromGameObject

<instance> updateFromGameObject()

Description:

Updates the Body's position, width, height, and center from its Game Object and offset.

You don't need to call this for Dynamic Bodies, as it happens automatically during the physics step. But you could use it if you have modified the Body offset or Game Object transform and need to immediately read the Body's new position or center.

To resynchronize the Body with its Game Object, use reset() instead.

Source: src/physics/arcade/Body.js#L1047
Since: 3.24.0


willDrawDebug

<instance> willDrawDebug()

Description:

Whether this Body will be drawn to the debug display.

Returns: boolean - True if either debugShowBody or debugShowVelocity are enabled.

Source: src/physics/arcade/Body.js#L1922
Since: 3.0.0