# Movement Commands


# Change Speed

  • Enum: number
Tag Description
Speed.Slowest 0.2
Speed.Slower 0.5
Speed.Slow 1
Speed.Normal 3
Speed.Fast 5
Speed.Faster 7
Speed.Fastest 10
  • Property: player.speed
  • Type: number
  • Optional: false
  • Default: 3
  • Usage:

Changes the player's speed

player.speed = 1

You can use Speed enum

import { Speed } from '@rpgjs/server'
player.speed = Speed.Slow

# Block movement

  • Property: player.canMove
  • Type: boolean
  • Optional: false
  • Default: true
  • Usage:

Blocks the movement. The player will not be able to move even if he presses the direction keys on the keyboard.

player.canMove = false

# Go through to other player

  • Property: player.throughOtherPlayer
  • Type: boolean
  • Optional: false
  • Default: true
  • Usage:

The player passes through the other players (or vice versa). But the player does not go through the events.

player.throughOtherPlayer = true

# Go through the player

  • Property: player.through
  • Type: boolean
  • Optional: false
  • Default: false
  • Usage:

The player goes through the event or the other players (or vice versa)

player.through = true

# Change Frequency

  • Enum: number
Tag Description
Frequency.Lowest 600
Frequency.Lower 400
Frequency.Low 200
Frequency.High 100
Frequency.Higher 50
Frequency.Highest 25
Frequency.None 0
  • Property: player.speed
  • Type: number
  • Optional: false
  • Default: 0
  • Usage:

The frequency allows to put a stop time between each movement in the array of the moveRoutes() method. The value represents a dwell time in milliseconds. The higher the value, the slower the frequency.

player.frequency = 400

You can use Frequency enum

import { Frequency } from '@rpgjs/server'
player.frequency = Frequency.Low

# Give an itinerary

  • Method: player.moveRoutes(routes)
  • Arguments:
    • {Array< Move>} routes. (Optional: false)
  • Return: Promise
  • Example:
import { Move } from '@rpgjs/server'

await player.moveRoutes([ Move.tileLeft(), Move.tileDown(2) ])
// The path is over when the promise is resolved
  • Usage:

Gives an itinerary.

You can create your own motion function:

import { Direction } from '@rpgjs/server'

const customMove = () => {
     return [Direction.Left, Direction.Up]
}

player.moveRoutes([ customMove() ])

Your function can also return a function:

import { Direction, RpgPlayer } from '@rpgjs/server'

// This function can be found in another file. By returning a function, you have access to the player who is making a move.
const customMove = (otherPlayer: RpgPlayer) => {
    return (player: RpgPlayer, map) => {
        return otherPlayer.position.x > player.position.x ? Direction.Left : Direction.Right
    }
}

player.moveRoutes([ customMove(otherPlayer) ])

the function contains two parameters:

  • player: the player concerned by the movement
  • map: The information of the current map

# Infinite Move Routes

  • Method: player.infiniteMoveRoute(routes)
  • Arguments:
    • {Array< Move>} routes. (Optional: false)
  • Return: void
  • Example:
import { Move } from '@rpgjs/server'

player.infiniteMoveRoute([ Move.tileRandom() ])
  • Usage:

Giving a path that repeats itself in a loop to a character

You can stop the movement at any time with breakRoutes() and replay it with replayRoutes().


# Stop an infinite movement

  • Method: player.breakRoutes(force=false)
  • Arguments:
    • {boolean} force. Forces the stop of the infinite movement (Optional: true)
  • Return: void
  • Example:
import { Move } from '@rpgjs/server'

player.infiniteMoveRoute([ Move.tileRandom() ])
player.breakRoutes(true)
  • Usage:

Works only for infinite movements. You must first use the method infiniteMoveRoute()


# Replay an infinite movement

  • Method: player.replayRoutes()
  • Return: void
  • Example:
import { Move } from '@rpgjs/server'

player.infiniteMoveRoute([ Move.tileRandom() ])
player.breakRoutes(true)
player.replayRoutes()
  • Usage:

Works only for infinite movements. You must first use the method infiniteMoveRoute() If the road was stopped with breakRoutes(), you can restart it with this method


# Move To

  • Since: 3.2.0
  • Method: player.moveTo()
  • Arguments:
    • { RpgPlayer RpgEvent RpgShape|Position} target. the target (Optional: false)
    • {object} options. - animate. Set a boolean to use default parameters (Optional: true)
    • {boolean} options.infinite. - moves infinitely towards the target, you have to stop its movement manually with the method stopMoveTo() (Optional: true)
    • {() => void} options.onComplete. - Callback when the event arrives at the destination (Optional: true)
    • {(duration:number) => void} options.onStuck. - callback when the event is blocked against a wall. Duration gives you the duration (in frames) of the blocking time (Optional: true)
  • Return: void
  • Example:
import { Move } from '@rpgjs/server'

player.moveTo(otherPlayer)
  • Usage:

Move the event to another event, a player, a shape or a specific position. The event will avoid obstacles, but you can tell if it is stuck or has completed its path


# Stop Move To

  • Since: 3.2.0
  • Method: player.stopMoveTo()
  • Return: void
  • Usage:

Stops the movement of the player who moves towards his target

# Movements List

All the movements below can be used in the moveRoutes() array.

Summary


# Move

  • Enum: Object
Tag Description
Move.right(repeat=1) Movement of a number of pixels on the right
Move.left(repeat=1) Movement of a number of pixels on the left
Move.up(repeat=1) Movement of a number of pixels on the up
Move.down(repeat=1) Movement of a number of pixels on the down
Move.random(repeat=1) Movement of a number of pixels in a random direction
Move.towardPlayer(player, repeat=1) Moves a number of pixels in the direction of the designated player
Move.awayFromPlayer(player, repeat=1) Moves a number of pixels in the opposite direction of the designated player
Move.tileRight(repeat=1) Movement of a number of tiles on the right
Move.tileLeft(repeat=1) Movement of a number of tiles on the left
Move.tileUp(repeat=1) Movement of a number of tiles on the up
Move.tileDown(repeat=1) Movement of a number of tiles on the down
Move.tileRandom(repeat=1) Movement of a number of tiles in a random direction
Move.tileTowardPlayer(player, repeat=1) Moves a number of tiles in the direction of the designated player
Move.tileAwayFromPlayer(player, repeat=1) Moves a number of tiles in the opposite direction of the designated player
Move.turnRight() Turn to the right
Move.turnLeft() Turn to the left
Move.turnUp() Turn to the up
Move.turnDown() Turn to the down
Move.turnRandom() Turn to random direction
Move.turnAwayFromPlayer(player) Turns in the opposite direction of the designated player
Move.turnTowardPlayer(player) Turns in the direction of the designated player
  • Usage:

The movement in number of pixels depends on the speed of the player.