Vision(owner)

Class for representing the vision component of a game entity.

new Vision(owner)

Constructs a new vision object.

Parameters:
Name Type Default Description
owner GameEntity null

The owner of this vision instance.

Author:

Members

fieldOfView :Number

The field of view in radians.

Default Value:
  • π

obstacles :Array.<GameEntity>

An array of obstacles. An obstacle is a game entity that implements the GameEntity#lineOfSightTest method.

nullable owner :GameEntity

The game entity that owns this vision instance.

Default Value:
  • null

range :Number

The visual range in world units.

Default Value:
  • Infinity

Methods

addObstacle(obstacle) → {Vision}

Adds an obstacle to this vision instance.

Parameters:
Name Type Description
obstacle GameEntity

The obstacle to add.

Returns:
Vision -

A reference to this vision instance.

fromJSON(json) → {Vision}

Restores this instance from the given JSON object.

Parameters:
Name Type Description
json Object

The JSON object.

Returns:
Vision -

A reference to this vision.

removeObstacle(obstacle) → {Vision}

Removes an obstacle from this vision instance.

Parameters:
Name Type Description
obstacle GameEntity

The obstacle to remove.

Returns:
Vision -

A reference to this vision instance.

resolveReferences(entities) → {Vision}

Restores UUIDs with references to GameEntity objects.

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

Maps game entities to UUIDs.

Returns:
Vision -

A reference to this vision.

toJSON() → {Object}

Transforms this instance into a JSON object.

Returns:
Object -

The JSON object.

visible(point) → {Boolean}

Performs a line of sight test in order to determine if the given point in 3D space is visible for the game entity.

Parameters:
Name Type Description
point Vector3

The point to test.

Returns:
Boolean -

Whether the given point is visible or not.