Skip to content

Entity Class

Entity is part of the KBEngine module. More...

import KBEngine

Member Functions

def moveToPoint( self, destination, velocity, distance, userData, faceMovement, moveVertically ):

def cancelController( self, controllerID ):

def isPlayer( self ):

def getComponent( self, componentName, all ):

def fireEvent( self, eventName, *args ):

def registerEvent( self, eventName, callback ):

def deregisterEvent( self, eventName, callback ):

Callback Functions

def onEnterWorld( self ):

def onLeaveWorld( self ):

def onEnterSpace( self ):

def onLeaveSpace( self ):

Properties

base read-only ENTITYCALL

cell read-only ENTITYCALL

className read-only string

clientapp read-only PyClientApp

direction Tuple of 3 floats as (roll, pitch, yaw)

id read-only Integer

position Vector3

spaceID read-only uint32

isOnGround read-only bool

Detailed Description

An instance of the Entity class represents a game object on the client.

An Entity can access its equivalent entity on the base and cell applications via ENTITYCALL. This requires a set of remote call functions (specified in the entity's .def file).

Member Function Documentation


def moveToPoint( self, destination, velocity, distance, userData, faceMovement, moveVertically ):

Description:

Moves the Entity in a straight line to the given coordinate point. On success or failure, a callback function is called.
Any Entity can only have one movement controller at any time; calling any movement function again will terminate the previous movement controller.
Returns a controller ID that can be used to cancel this movement.

For example:
Entity.cancelController(movementID). Movement can also be cancelled by calling Entity.cancelController("Movement"). After movement is cancelled, notification methods will not be called.

Callback functions are defined as follows:

py
def onMove( self, controllerID, userData ):
def onMoveOver( self, controllerID, userData ):
def onMoveFailure( self, controllerID, userData ):

See also:

Entity.cancelController

Parameters:

destination: Vector3, the target position to move the Entity to

velocity: float, the movement speed of the Entity, in m/s

distance: float, stop moving when closer than this distance to the target; if 0, move to the target position.

userData: object, data passed to the notification function

faceMovement: bool, true if the entity faces the movement direction, false for other mechanisms.

moveVertically: bool, true for straight-line movement, false for ground-following movement.

Returns:

int, the newly created controller ID.


def cancelController( self, controllerID ):

Description:

The cancelController function stops a controller's effect on the Entity. It can only be called on a real entity.

Parameters:

controllerID: controllerID is the index of the controller to cancel, an integer. A string representing a specific controller type can also be used. For example, only one movement/navigation controller can be active at a time, which can be cancelled with entity.cancelController("Movement").


def isPlayer( self ):

Description:

This function returns whether this Entity is the Player controlled by the current client.

Returns:

bool, True if it is the Player controlled by the current client, otherwise False.


def getComponent( self, componentName, all ):

Description:

This function is used to get instances of a certain type of component bound to the entity.

Parameters:

componentName: string, the component type name, i.e., the module name of the component.

all: bool, if True, returns all instances of the same component type, otherwise returns only the first or an empty list.


def fireEvent( self, eventName, *args ):

Description:

This function is used to trigger an entity event.

Parameters:

eventName: string, the name of the event to trigger.

args: event data to attach, variable arguments.


def registerEvent( self, eventName, callback ):

Description:

This function is used to register an entity event.

Parameters:

eventName: string, the name of the event to listen for.

callback: the callback method to respond to the event when triggered.


def deregisterEvent( self, eventName, callback ):

Description:

This function is used to unregister an entity event listener.

Parameters:

eventName: string, the name of the event to unregister.

callback: the callback method to unregister.

Callback Function Documentation


def onEnterWorld( self ):

If the entity is not a client-controlled entity, it means the entity has entered the View range of a client-controlled entity on the server, and the client can now see this entity.
If the entity is a client-controlled entity, it means the entity has created a cell on the server and entered the space.


def onLeaveWorld( self ):

If the entity is not a client-controlled entity, it means the entity has left the View range of a client-controlled entity on the server, and the client can no longer see this entity.
If the entity is a client-controlled entity, it means the entity's cell has been destroyed on the server and it has left the space.


def onEnterSpace( self ):

A client-controlled entity has entered a new space.


def onLeaveSpace( self ):

A client-controlled entity has left the current space.

Property Documentation


base

base is the entityCall used to contact the Entity entity. This property is read-only, and if this entity does not have an associated Entity, the property is None.

See also:

Entity.clientEntity
Entity.allClients
Entity.otherClients

Type:

read-only ENTITYCALL


cell

Description:

cell is the ENTITYCALL used to contact the cell entity. This property is read-only, and if this base entity does not have an associated cell, the property is None.

Type:

read-only ENTITYCALL


cellData

Description:

cellData is a dictionary property. Whenever the base entity has not created its cell entity, the cell entity's properties are stored here.

If the cell entity is created, these values and the cellData property will be deleted. In addition to the properties specified in the entity definition file, it also contains position, direction, and spaceID.

Type:

CELLDATADICT


className

Description:

The class name of the entity.

Type:

read-only string


clientapp

Description:

The client (object) to which the current entity belongs.

Type:

read-only PyClientApp


position

The coordinates (x, y, z) of this entity in world space, data is synchronized from the server to the client.

Type:

Vector3


direction

This property describes the orientation of the Entity in world space, data is synchronized from the server to the client.

Type:

Vector3, containing (roll, pitch, yaw), in radians.


isOnGround

If this property is True, the Entity is on the ground, otherwise False.

If it is a client-controlled entity, this property will be synchronized to the server when changed; for other entities, it is synchronized from the server to the client. The client can use this value to force ground contact to avoid precision issues.

Type:

read/write, bool

文档内容由 Comblock® 提供