Trigger(region)

Base class for representing triggers. A trigger generates an action if a game entity touches its trigger region, a predefine area in 3D space.

new Trigger(region)

Constructs a new trigger with the given values.

Parameters:
Name Type Description
region TriggerRegion

The region of the trigger.

Author:

Extends

Members

active :Boolean

Whether this game entity is active or not.

Overrides:
Default Value:
  • true

boundingRadius :Number

The bounding radius of this game entity in world units.

Overrides:
Default Value:
  • 0

canActivateTrigger :Boolean

Whether the entity can activate a trigger or not.

Overrides:
Default Value:
  • true

children :Array.<GameEntity>

The child entities of this game entity.

Overrides:

forward :Vector3

The default forward vector of this game entity.

Overrides:
Default Value:
  • (0,0,1)

readonly manager :EntityManager

A reference to the entity manager of this game entity. Automatically set when added to an EntityManager.

Overrides:
Default Value:
  • null

maxTurnRate :Number

The maximum turn rate of this game entity in radians per seconds. The only method that uses this property right now is GameEntity#rotateTo.

Overrides:
Default Value:
  • π

name :String

The name of this game entity.

Overrides:

neighborhoodRadius :Number

Game entities within this radius are considered as neighbors of this entity.

Overrides:
Default Value:
  • 1

readonly neighbors :Array.<GameEntity>

A list of neighbors of this game entity.

Overrides:

readonly, nullable parent :GameEntity

A reference to the parent entity of this game entity. Automatically set when added to a GameEntity.

Overrides:
Default Value:
  • null

position :Vector3

The position of this game entity.

Overrides:

region :TriggerRegion

The region of the trigger.

rotation :Quaternion

The rotation of this game entity.

Overrides:

scale :Vector3

The scaling of this game entity.

Overrides:

up :Vector3

The default up vector of this game entity.

Overrides:
Default Value:
  • (0,1,0)

updateNeighborhood :Boolean

Whether the neighborhood of this game entity is updated or not.

Overrides:
Default Value:
  • false

readonly uuid :String

Unique ID, primarily used in context of serialization/deserialization.

Overrides:

readonly worldMatrix :Matrix4

A transformation matrix representing the world space of this game entity.

Overrides:

Methods

add(entity) → {GameEntity}

Adds a game entity as a child to this game entity.

Parameters:
Name Type Description
entity GameEntity

The game entity to add.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

check(entity) → {Trigger}

This method is called per simulation step for all game entities. If the game entity touches the region of the trigger, the respective action is executed.

Parameters:
Name Type Description
entity GameEntity

The entity to test

Returns:
Trigger -

A reference to this trigger.

execute(entity) → {Trigger}

This method is called when the trigger should execute its action. Must be implemented by all concrete triggers.

Parameters:
Name Type Description
entity GameEntity

The entity that touched the trigger region.

Returns:
Trigger -

A reference to this trigger.

fromJSON(json) → {Trigger}

Restores this instance from the given JSON object.

Parameters:
Name Type Description
json Object

The JSON object.

Returns:
Trigger -

A reference to this trigger.

Overrides:

getDirection(result) → {Vector3}

Computes the current direction (forward) vector of this game entity and stores the result in the given vector.

Parameters:
Name Type Description
result Vector3

The direction vector of this game entity.

Returns:
Vector3 -

The direction vector of this game entity.

Overrides:

getWorldDirection(result) → {Vector3}

Computes the current direction (forward) vector of this game entity in world space and stores the result in the given vector.

Parameters:
Name Type Description
result Vector3

The direction vector of this game entity in world space.

Returns:
Vector3 -

The direction vector of this game entity in world space.

Overrides:

getWorldPosition(result) → {Vector3}

Computes the current position of this game entity in world space and stores the result in the given vector.

Parameters:
Name Type Description
result Vector3

The position of this game entity in world space.

Returns:
Vector3 -

The position of this game entity in world space.

Overrides:

handleMessage(telegram) → {Boolean}

Holds the implementation for the message handling of this game entity.

Parameters:
Name Type Description
telegram Telegram

The telegram with the message data.

Returns:
Boolean -

Whether the message was processed or not.

Overrides:

lineOfSightTest(ray, intersectionPoint) → {Vector3}

Holds the implementation for the line of sight test of this game entity. This method is used by Vision#visible in order to determine whether this game entity blocks the given line of sight or not. Implement this method when your game entity acts as an obstacle.

Parameters:
Name Type Description
ray Ray

The ray that represents the line of sight.

intersectionPoint Vector3

The intersection point.

Returns:
Vector3 -

The intersection point.

Overrides:

lookAt(target) → {GameEntity}

Directly rotates the entity so it faces the given target position.

Parameters:
Name Type Description
target Vector3

The target position.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

registerType(type, constructor) → {Trigger}

Registers a custom type for deserialization. When calling Trigger#fromJSON the trigger is able to pick the correct constructor in order to create custom trigger regions.

Parameters:
Name Type Description
type String

The name of the trigger region.

constructor function

The constructor function.

Returns:
Trigger -

A reference to this trigger.

remove(entity) → {GameEntity}

Removes a game entity as a child from this game entity.

Parameters:
Name Type Description
entity GameEntity

The game entity to remove.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

resolveReferences(entities) → {GameEntity}

Restores UUIDs with references to GameEntity objects.

Parameters:
Name Type Description
entities Map.<String, GameEntity>

Maps game entities to UUIDs.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

rotateTo(target, delta, tolerance) → {Boolean}

Given a target position, this method rotates the entity by an amount not greater than GameEntity#maxTurnRate until it directly faces the target.

Parameters:
Name Type Default Description
target Vector3

The target position.

delta Number

The time delta.

tolerance Number 0.0001

A tolerance value in radians to tweak the result when a game entity is considered to face a target.

Returns:
Boolean -

Whether the entity is faced to the target or not.

Overrides:

sendMessage(receiver, message, delay, data) → {GameEntity}

Sends a message with the given data to the specified receiver.

Parameters:
Name Type Default Description
receiver GameEntity

The receiver.

message String

The actual message.

delay Number 0

A time value in millisecond used to delay the message dispatching.

data Object null

An object for custom data.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

setRenderComponent(renderComponent, callback) → {GameEntity}

Sets a renderable component of a 3D engine with a sync callback for this game entity.

Parameters:
Name Type Description
renderComponent Object

A renderable component of a 3D engine.

callback function

A callback that can be used to sync this game entity with the renderable component.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

start() → {GameEntity}

Executed when this game entity is updated for the first time by its EntityManager.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

toJSON() → {Object}

Transforms this instance into a JSON object.

Returns:
Object -

The JSON object.

Overrides:

update(delta) → {GameEntity}

Updates the internal state of this game entity. Normally called by EntityManager#update in each simulation step.

Parameters:
Name Type Description
delta Number

The time delta.

Returns:
GameEntity -

A reference to this game entity.

Overrides:

updateRegion() → {Trigger}

Updates the region of this trigger. Called by the EntityManager per simulation step.

Returns:
Trigger -

A reference to this trigger.