Phaser API Documentation

  Version: 
accelerateToObject(gameObject, destination, [speed], [xSpeedMax], [ySpeedMax])

Description:

Sets the acceleration.x/y property on the game object so it will move towards the x/y coordinates at the given rate (in pixels per second squared)

You must give a maximum speed value, beyond which the game object won't go any faster.

Note: The game object does not continuously track the target. If the target changes location during transit the game object will not modify its course. Note: The game object doesn't stop moving once it reaches the destination coordinates.

Parameters:

name type arguments Default description
gameObject Phaser.GameObjects.GameObject

Any Game Object with an Arcade Physics body.

destination Phaser.GameObjects.GameObject

The Game Object to move towards. Can be any object but must have visible x/y properties.

speed number <optional> 60

The acceleration (change in speed) in pixels per second squared.

xSpeedMax number <optional> 500

The maximum x velocity the game object can reach.

ySpeedMax number <optional> 500

The maximum y velocity the game object can reach.

Returns:
Description:

The angle (in radians) that the object should be visually set to in order to match its new velocity.

Type:
  • number
Since: 3.0.0