Skip to main content

Entity

Provides properties and functions to interact with an Entity in the world.

Properties

isEntity

Indicates whether the object is an Entity. This property is read-only.

name

Gets the name of the entity.

isInvulnerable

Determines whether the entity can take damage. Setting to false will allow the entity to lose health when hit by weapons or hazards. Setting to true will prevent the entity from losing health.

id

Gets the ID of the entity — every entity in the world has a unique ID. This property is read-only.

entityId

Gets the code (a string value) used to identify the type of the entity. This can be used to spawn copies of an entity. This property is read-only.

isDestroyed

Returns true if the entity is destroyed. This property is read-only.

useGravity

Determines whether the entity is affected by gravity.

isKinematic

Determines whether physics affects the entity.

velocity

Gets or sets the velocity of the entity.

angularVelocity

Gets or sets the angular velocity of the entity (measured in radians per second).

drag

Gets or sets the drag factor of the entity. Drag determines the amount of resistance applied to the linear motion of the entity. This can be used to slow down an entity — the higher the drag, the more slowly an entity moves.

angularDrag

Gets or sets the angular drag factor of the entity. Angular drag determines the amount of resistance applied to the rotational motion of the entity. This can be used to slow down rotation of an entity — the higher the drag, the more slowly an entity rotates.

env

Gets the Lua environment of the entity. This property is read-only.

isPlayer

Indicates whether the object is a Player. This property is read-only.

networkId

Gets the network ID of the object. This property is read-only.

forward

Gets forward vector of the object. This property is read-only.

position

Gets/sets the current position.

rotation

Gets/sets the current rotation (in degrees).

scale

Sets the current scale.

onDestroy

Assigns a function that will be called when the object is destroyed. This property is write-only.

onDamage

Assigns a function that will be called when the object receives damage. This property is write-only.

onSensorEnter

Assigns a function that will be called when an object enters the sensor. This property is write-only.

onSensorExit

Assigns a function that will be called when an object leaves the sensor. This property is write-only.

onScriptReload

Assigns a function that will be called when the script assigned to the object changes. This property is write-only.

Functions

addForce(force, forceMode)

Applies a force to the entity.

Parameters

  • force The force vector. E.g. {0,1,0} for a force in the vertical 'up' direction.
  • forceMode The ForceMode.

addTorque(force, forceMode)

Applies a torque force to the entity.

Parameters

  • force The torque vector. E.g. {0,1,0} for a torque that turns the entity anti-clockwise around the y-axis.
  • forceMode The ForceMode.

getStringProperty(propertyName)

Attempts to get a string value from the entity's payload.

Parameters

  • propertyName Name of the property.

Returns

Property value or null if property was not found.


getNumberProperty(propertyName)

Attempts to get a number value from the entity's payload.

Parameters

  • propertyName Name of the property.

Returns

Property value or -1 if property was not found.


getVector2Property(propertyName)

Attempts to get a Vector2 value from the entity's payload.

Parameters

  • propertyName Name of the property.

Returns

Property value or (0,0) if property was not found.


getVector3Property(propertyName)

Attempts to get a Vector3 value from the entity's payload.

Parameters

  • propertyName Name of the property.

Returns

Property value or (0,0,0) if property was not found.


getVector4Property(propertyName)

Attempts to get a Vector4 value from the entity's payload.

Parameters

  • propertyName Name of the property.

Returns

Property value or (0,0,0,0) if property was not found.


getColorProperty(propertyName)

Attempts to get a color value from the entity's payload.

Parameters

  • propertyName Name of the property.

Returns

Property value or a clear color if property was not found.


getBoolProperty(propertyName)

Attempts to get a boolean value from the entity's payload.

Parameters

  • propertyName Name of the property.

Returns

Property value or false if property was not found.


setStringProperty(propertyName, value)

Adds or updates a string value in the entity's payload.

Parameters

  • propertyName Name of the property.
  • value Value to assign.

setNumberProperty(propertyName, value)

Adds or updates a number value in the entity's payload.

Parameters

  • propertyName Name of the property.
  • value Value to assign.

setBoolProperty(propertyName, value)

Adds or updates a boolean value in the entity's payload.

Parameters

  • propertyName Name of the property.
  • value Value to assign.

setVector2Property(propertyName, value)

Adds or updates a Vector2 value in the entity's payload.

Parameters

  • propertyName Name of the property.
  • value Value to assign.

setVector3Property(propertyName, value)

Adds or updates a Vector3 value in the entity's payload.

Parameters

  • propertyName Name of the property.
  • value Value to assign.

setVector4Property(propertyName, value)

Adds or updates a Vector4 value in the entity's payload.

Parameters

  • propertyName Name of the property.
  • value Value to assign.

setColorProperty(propertyName, value)

Adds or updates a Color value in the entity's payload.

Parameters

  • propertyName Name of the property.
  • value Value to assign.

copyCustomProperties(otherTarget)

Copies custom properties from one entity to another. Matching property names will be overwritten.

Parameters

  • otherTarget

invoke(methodName, value, asyncMode)

Invokes the function with the given name on the entity.

Parameters

  • methodName The name of the function to invoke.
  • value Optional data to pass to the function.
  • asyncMode The AsyncMode which determines whether the program should wait for the function to complete before continuing.

destroy()

Destroys the object.