AISystem Class
System responsible for processing AI entities. It triggers the same events as the keyboard input system and controlls AI entities that way. Thanks to this, the logic used for controlling the player character can be reused by the AI scripts. The system requires only the AI component to be present, but the various scripts may require more than that to function.
Constructor
AISystem
-
entitySystemManager
-
physicsSystem
-
collisionMasks
Parameters:
-
entitySystemManager
ManagerThe entity system manager whose entities this system will be working on.
-
physicsSystem
PhysicsSystemThe physics system is used for various world queries.
-
collisionMasks
ObjectAn object holding bit masks used for determining collision categories.
Methods
destroy
()
disable
()
Disables the processing of all AI entities.
enable
()
Enables the processing of all AI entities.
subscribe
-
event
-
callback
-
[subscriber]
Parameters:
-
event
StringName of the event being subscribed to.
-
callback
FunctionFunction that will be called back when the specified event is triggered.
-
[subscriber]
Object optionalAn optional parameter that specifies an object that's subscribing. When a function is subscribed with an object, that function will be called back with "this" set to the object.
trigger
-
event
-
[eventObject]
Triggers the event, calling all functions that subscribed to it.
Parameters:
-
event
StringThe event to be triggered.
-
[eventObject]
Object optionalAll functions that were subscribed to the specified event will be called with this as the argument.
unsubscribe
-
event
-
[callback]
-
[subscriber]
This is a multi-purpose method. See the example for all the ways it can be overloaded.
Parameters:
-
event
Object -
[callback]
Object optional -
[subscriber]
Object optional
Example:
//Unsubscribing all callbacks for a given event.
eventHandler.unsubscribe('eventName');
//Unsubscribing all callbacks subscribed by the object.
eventHandler.unsubscribe(object);
//Unsubscribing all callbacks an object made for the given event.
eventHandler.unsubscribe('eventName', object);
//Unsubscribing a callback that was subscribed with an object.
eventHandler.unsubscribe('eventName', callback, object);
//Unsubscribing a callback subscribed by itself.
eventHandler.unsubscribe('eventName', callback);
//The last method can't be used to unsubscribe callbacks which were subscribed with an object.
update
-
deltaTime
Updates all AI entities by processing scripts they have attached.
Parameters:
-
deltaTime
Number