Skip to main content

Rotation

Contains functions for controlling the rotation of a moveable Entity.

info

This module can only be used in Entity scripts.

Functions

turn(turns, asyncMode)

Turn 90-degrees the specified number of times clockwise/counter-clockwise.

Parameters

  • turns The number of times to turn 90-degrees.
  • asyncMode The AsyncMode which determines whether the task should wait for the function to complete before continuing.

Example

Turn 180 degrees.

function onStart()
Rotation.turn(2)
end

face(bearing, asyncMode)

Turn to face the specified direction.

Parameters

  • bearing The Bearing direction to face.
  • asyncMode The AsyncMode which determines whether the task should wait for the function to complete before continuing.

Example

Patrol in a square shape with 2x2 units of area.

function onStart()
while true do
Rotation.face(Bearing.North)
Movement.moveForward(2)
Rotation.face(Bearing.East)
Movement.moveForward(2)
Rotation.face(Bearing.South)
Movement.moveForward(2)
Rotation.face(Bearing.West)
Movement.moveForward(2)
Task.wait(1)
end
end

faceForward(asyncMode)

Turn to face the current direction of motion.

Parameters

  • asyncMode The AsyncMode which determines whether the task should wait for the function to complete before continuing.

Example

Change the velocity of an Entity and make it face that direction.

function onStart()
while true do
self.velocity = Vector3.new(1,0,1)
Rotation.faceForward(AsyncMode.Continue)
Task.yield()
end
end

facePlayer(asyncMode)

Turn to face the nearest player.

Parameters

  • asyncMode The AsyncMode which determines whether the task should wait for the function to complete before continuing.

Example

Make an Entity always look at the player.

function onStart()
while true do
Rotation.facePlayer()
end
end

turnTo(position, asyncMode)

Turn to the specified position.

Parameters

  • position A Vector3 containing the position to face.
  • asyncMode The AsyncMode which determines whether the task should wait for the function to complete before continuing.

Example

Make an Entity face (10,0,0), wait 2 seconds and then face (-10,0,0).

function onStart()
Rotation.turnTo(Vector3.new(10,0,0))
Task.wait(2)
Rotation.turnTo(Vector3.new(-10,0,0))
end

stop()


isTurning()

Returns true if the Entity is currently turning.

Returns

A boolean.

Example

Update the console text if is turning or not.

function onStart()
Rotation.turn(3, AsyncMode.Continue)
while true do
if Rotation.isTurning() then
Hud.console.write("woooo")
else
Hud.console.write('finally is over')
break
end
Task.yield()
end
end

isFacing(direction)

Returns true if the Entity is facing the specified direction.

Parameters

  • direction The Bearing direction.

Returns

A boolean.

Example

Write on console if is facing north and stop turning.

function isFacingNorth()
return Rotation.isFacing(Bearing.North)
end

function onStart()
Rotation.turn(3, AsyncMode.Continue)

while true do
if isFacingNorth() then
Rotation.stop()
Hud.console.write("is facing north")
break
end
Task.yield()
end
end