Skip to main content

Movement

Contains functions for controlling motion of a moveable Entity.

info

This module can only be used in Entity scripts.

Functions

move(bearing, asyncMode)

Moves one unit in the specified direction.

Parameters

  • bearing The Bearing direction to move.
  • asyncMode The AsyncMode which determines whether the program should wait for the function to complete before continuing.
    • Default: AsyncMode.Wait

Example

Make an Entity walk in a square forever.

function onStart()
while true do
Movement.move(Bearing.North)
Movement.move(Bearing.East)
Movement.move(Bearing.South)
Movement.move(Bearing.West)
end
end

moveForward(steps, asyncMode)

Moves one unit in the direction the Entity is currently facing.

Parameters

  • steps The number of steps to move. Specify a negative number to move backwards.
    • Default: 1
  • asyncMode The AsyncMode which determines whether the program should wait for the function to complete before continuing.
    • Default: AsyncMode.Wait

Example

Make an Entity walk back and forward 2 units forever.

function onStart()
while true do
Movement.moveForward(2)
Rotation.turn(2)
end
end

moveTo(position, asyncMode)

Moves to the specified position, using navigation.

Parameters

  • position A Vector3 containing the position to move to.
  • asyncMode The AsyncMode which determines whether the program should wait for the function to complete before continuing.
    • Default: AsyncMode.Wait

Example

Make an Entity patrol between defined positions in the world.

function onStart()
Movement.moveTo(Vector3.new(-11,0,-3))
Movement.moveTo(Vector3.new(-13,0,-3))
Movement.moveTo(Vector3.new(-13,0,-5))
Movement.moveTo(Vector3.new(-11,0-5))
end

moveToPlayer(asyncMode)

Moves to the nearest player, using navigation.

Parameters

  • asyncMode The AsyncMode which determines whether the program should wait for the function to complete before continuing.
    • Default: AsyncMode.Wait

Example

Make an Entity chase the closest player forever.

function onStart()
while true do
Movement.moveToPlayer(AsyncMode.Continue)
Task.yield()
end
end

moveBy(vector, asyncMode)

Moves by the specified number of units in the x, y, and z axis.

Parameters

  • vector A Vector3 containing the displacement to move by.
  • asyncMode The AsyncMode which determines whether the program should wait for the function to complete before continuing.
    • Default: AsyncMode.Wait

Example

Make an Entity move back and forth forever.

function onStart()
while true do
Movement.moveBy(Vector3.new(-1,0,0))
Movement.moveBy(Vector3.new(1,0,0))
end
end

stop()

Stops any movement command previously started on the Entity.

Example

Stops an NPC when the player interacts with it, then when the interaction finish, make the NPC go back to patrolling.

function onInteractStart(clientId)
Movement.stop()
end
function onInteractFinish(clientId)
patrol() -- local function on the NPC
end

setSpeed(speed)

Sets the speed of motion.

Parameters

  • speed The value to set the speed to - this will determine how fast the object moves.

Example

Make the Entity go back and forth at different speeds.

function onStart()
while true do
Movement.setSpeed(2)
Movement.moveTo({-10,0,-6})
Movement.setSpeed(6)
Movement.moveTo({-14,0,-2})
end
end

isMoving()

Returns true if the Entity is currently moving.

Returns

A boolean.

Example

Change the dialogue if the NPC is moving or not.

function onInteractStart(clientId)
if Movement.isMoving() then
Speech.prompt("Hey! can't you see I'm busy")
else
Speech.prompt("Hi! how can I help you?")
end
-- for more info about dialogues go to the Speech module
end