new GameEntity()
Constructs a new game entity.
Members
-
active :Boolean
-
Whether this game entity is active or not.
- Default Value:
- true
-
boundingRadius :Number
-
The bounding radius of this game entity in world units.
- Default Value:
- 0
-
canActivateTrigger :Boolean
-
Whether the entity can activate a trigger or not.
- Default Value:
- true
-
children :Array.<GameEntity>
-
The child entities of this game entity.
-
forward :Vector3
-
The default forward vector of this game entity.
- 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.
- 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.
- Default Value:
- π
-
name :String
-
The name of this game entity.
-
neighborhoodRadius :Number
-
Game entities within this radius are considered as neighbors of this entity.
- Default Value:
- 1
-
readonly neighbors :Array.<GameEntity>
-
A list of neighbors of this game entity.
-
readonly, nullable parent :GameEntity
-
A reference to the parent entity of this game entity. Automatically set when added to a GameEntity.
- Default Value:
- null
-
position :Vector3
-
The position of this game entity.
-
rotation :Quaternion
-
The rotation of this game entity.
-
scale :Vector3
-
The scaling of this game entity.
-
up :Vector3
-
The default up vector of this game entity.
- Default Value:
- (0,1,0)
-
updateNeighborhood :Boolean
-
Whether the neighborhood of this game entity is updated or not.
- Default Value:
- false
-
readonly uuid :String
-
Unique ID, primarily used in context of serialization/deserialization.
-
readonly worldMatrix :Matrix4
-
A transformation matrix representing the world space of this game entity.
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.
-
fromJSON(json) → {GameEntity}
-
Restores this instance from the given JSON object.
Parameters:
Name Type Description json
Object The JSON object.
-
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.
-
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.
-
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.
-
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.
-
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.
-
lookAt(target) → {GameEntity}
-
Directly rotates the entity so it faces the given target position.
Parameters:
Name Type Description target
Vector3 The target position.
-
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.
-
resolveReferences(entities) → {GameEntity}
-
Restores UUIDs with references to GameEntity objects.
Parameters:
Name Type Description entities
Map.<String, GameEntity> Maps game entities to UUIDs.
-
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.
-
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.
-
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.
-
start() → {GameEntity}
-
Executed when this game entity is updated for the first time by its EntityManager.
-
toJSON() → {Object}
-
Transforms this instance into a JSON object.
Returns:
Object -The JSON object.
-
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.