User Tools

Site Tools


dragengine:modules:dragonscript:behavior_actoraiaction

ECBehaviorActorAIAction

Behavior adding AI and Action support to actors.

Allows instance of BaseActorAction and BaseActorAI to be assigned to actor. During thinking first the AI then the Action is called.

Actions allow actors to perform a specific, well defined and enclosed action like interacting with an object. Actions are suitable to be used by player and computer controlled actors alike. This concept allows using the same actions for both player and computer controlled actors reducing coding effort, misbehavior and overall ensures that what a player can do a computer controlled actor can do and vice versa.

AIs allow computer controlled actors to act on their own. With player controlled actors the AI is skipped and the player is the AI. AI provides long running actor actions like guarding a zone with the possiblity to switch between different actions depending on how the actor wants to react to events. This separation makes it simple to design AI in coarse grain placing actual small grained actions into reusable action instances. This separation also allows actors to easily switch between player and computer controlled because both can reuse the same action instances.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix aiAction..

Events

Since this behavior provides no support to apply the chosen color listening is used. Behaviors knowing how to apply the color add a listener and are notified if the color changes. These events can be received:

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable). Saves active action and AI object.

API Documentation

ECBehaviorActorAIAction.

Since DragonScript Module Version 1.0

Use Cases

  • Add action and AI support to actors.

Element Class Example

This example defines an element which action and AI support.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorColliderAI colliderAI
  public var ECBehaviorConversationActor conversationActor
  public var ECBehaviorPlayerControllable playerControllable
  public var ECBehaviorActorAIAction aiAction
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    colliderAI = ECBehaviorColliderAI.new(this, collider)
    conversationActor = ECBehaviorConversationActor.new(this)
    playerControllable = ECBehaviorPlayerControllable.new(this)
    playerControllable.setConversationActor(conversationActor)
    aiAction = ECBehaviorActorAIAction.new(this, colliderAI, conversationActor, pPlayerControllable)
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
  <behavior type='ECBehaviorColliderAI'/>
  <behavior type='ECBehaviorConversationActor'/>
  <behavior type='ECBehaviorPlayerControllable'/>
 
  <behavior type='ECBehaviorActorAIAction'>
    <!-- behavior factory automatically assigns all optional behaviors if present -->
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorActorAIAction' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_actoraiaction.txt · Last modified: 2025/03/12 19:37 by dragonlord