Physics.Arcade.Body#moveTo()

moveTo(duration, distance, direction) → {boolean}

Note: This method is experimental, and may be changed or removed in a future release.

This method moves the Body in the given direction, for the duration specified.
It works by setting the velocity on the Body, and an internal distance counter.
The distance is monitored each frame. When the distance equals the distance
specified in this call, the movement is stopped, and the Body.onMoveComplete
signal is dispatched.

Movement also stops if the Body collides or overlaps with any other Body.

You can control if the velocity should be reset to zero on collision, by using
the property Body.stopVelocityOnCollide.

Stop the movement at any time by calling Body.stopMovement.

Please note that due to browser timings you should allow for a variance in
when the distance will actually expire.

Note: This method doesn't take into consideration any other forces acting
on the Body, such as Gravity, drag or maxVelocity, all of which may impact the
movement.

Parameters
Name Type Argument Description
duration integer

The duration of the movement, in ms.

distance integer

The distance, in pixels, the Body will move.

direction integer <optional>

The angle of movement. If not provided Body.angle is used.

Returns
boolean -

True if the movement successfully started, otherwise false.

Source code: physics/arcade/Body.js (Line 953)
doc_phaser
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.