User Tools

Site Tools


dragengine:modules:dragonscript:behavior_actoranimated

ECBehaviorActorAnimated

Behavior adding animation support to actors.

Adds AnimatorInstance and a map of animators to switch using string identifiers.

To simplify using actor animation a map of controller bindings can be defined to be applied to ECBehaviorLocomotion each time the animator changes. This requires controller names to be consistent and unique across animators but makes life a lot easier. If no map is defined the behavior does not change the locomotion controller mapping. While changing animator controllers with matching names are not reset.

See also:

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix actorAnimated..

animators

Set animators which is a mpa between identifier and animator path. Allows selecting animator to use using the identifier.

  • Full name: actorAnimated.animators
  • Type: map
  • Default Value: empty string
  • Example (*.deeclass)

    <map name='actorAnimated.animators'>
      <string key='default'>default.deanimator</string>
      <string key='sitting'>sitting.deanimator</string>
      <string key='flying'>flying.deanimator</string>
    </map>

Events

This behavior has these events:

updateControllers

Listener can update controllers if required.

animationApplied

Animation has been applied.

animatorChanged

Animator changed. Listener has to reacquire AnimatorController.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace actorAnimated with actorAnimated(id).

actorAnimated.set

Set one or more actor animated parameters.

ParameterValueDescription
animatorstringSet animator by identifier
controller.namestringName of controller to manipulate
controller.valuefloatSet current value of controller controller.name
controller.value.incrementfloatIncrement current value of controller controller.name
controller.value.decrementfloatDecrement current value of controller controller.name
controller.value.relativefloatSet relative current value of controller controller.name in the range from 0 to 1
controller.value.relative.incrementfloatIncrement relative current value of controller controller.name
controller.value.relative.decrementfloatDecrement relative current value of controller controller.name
controller.value.lowerfloatSet current value of controller controller.name to lower value
controller.value.upperfloatSet current value of controller controller.name to upper value
controller.value.reverse Reverse current value of controller controller.name. Hence upper becomes lower and vice versa

This is an example of using this action:

<action name='actorAnimated.set'>
  <parameter name='animator'>open door</parameter>
</action>

actorAnimated.check

Check one or more actor animated parameters. Action succeeds if all parameter value matches their respective actor animated parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a actor animated parameter matches (or not).

ParameterValueDescription
animatorstringAnimator identifier matches string value
animator.notstringAnimator identifier does not match string value
animator.startsstringAnimator identifier start with string value
animator.starts.notstringAnimator identifier does not start with string value
animator.endsstringAnimator identifier ends with string value
animator.ends.notstringAnimator identifier does not end with string value
animator.containsstringAnimator identifier contains string value
animator.contains.notstringAnimator identifier does not contain string value
controller.namestringName of controller to evaluate
controller.value.lessfloatCurrent value of controller is less than float value
controller.value.greaterfloatCurrent value of controller is greater than float value
controller.value.relative.lessfloatRelative current value of controller is less than float value
controller.value.relative.greaterfloatRelative current value of controller is greater than float value
controller.value.atLower Current value of controller is at lower value
controller.value.atUpper Current value of controller is at upper value
wait If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled

This is an example of using this action:

<sequence>
  <action name='actorAnimated.check'>
    <parameter name='animator'>open door</parameter>
  </action>
  <!-- actions here run only if active animator has identifier "open door" -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace actorAnimated with actorAnimated(id).

actorAnimated.check

Check one or more actor animated parameters. Conditions returns true if all parameter value match their respective actor animated parameter. This condition is typically used to run an action or sequence of actions as long as actor animated conditions are true.

ParameterValueDescription
actorAnimated.animatorstringAnimator identifier matches string value
actorAnimated.animator.notstringAnimator identifier does not match string value
actorAnimated.animator.startsstringAnimator identifier start with string value
actorAnimated.animator.starts.notstringAnimator identifier does not start with string value
actorAnimated.animator.endsstringAnimator identifier ends with string value
actorAnimated.animator.ends.notstringAnimator identifier does not end with string value
actorAnimated.animator.containsstringAnimator identifier contains string value
actorAnimated.animator.contains.notstringAnimator identifier does not contain string value
actorAnimated.controller.namestringName of controller to evaluate
actorAnimated.controller.value.lessfloatCurrent value of controller is less than float value
actorAnimated.controller.value.greaterfloatCurrent value of controller is greater than float value
actorAnimated.controller.value.relative.lessfloatRelative current value of controller is less than float value
actorAnimated.controller.value.relative.greaterfloatRelative current value of controller is greater than float value
actorAnimated.controller.value.atLower Current value of controller is at lower value
actorAnimated.controller.value.atUpper Current value of controller is at upper value

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='actorAnimated.animator'>open door</parameter>
  <condition>actorAnimated.check</condition>
</action>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends these state machine events. If behavior has non-empty identifier replace actorAnimated with actorAnimated(id).

This behavior has these events:

actorAnimated.animator

Animator changed.

Required Behaviors

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorActorAnimated.

Since DragonScript Module Version 1.0

Use Cases

  • Animate actors by seleting animators from a predefined map of animators.
  • Animate actors using custom runtime assigned animator.

Element Class Example

This example defines an element which animated an actor.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorColliderAI colliderAI
  public var ECBehaviorLocomotion locomotion
  public var ECBehaviorActorAnimated actorAnimated
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    colliderAI = ECBehaviorColliderAI.new(this, collider)
    locomotion = ECBehaviorLocomotion.new(this, colliderAI)
    actorAnimatord = ECBehaviorActorAnimated.new(this, component, locomotion)
  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='ECBehaviorActorAnimated'>
    <!-- optional: use component with id instead of empty string -->
    <string name='component'>second</string>
 
    <!-- optional: use behavior tree with id instead of empty string -->
    <string name='behaviorTree'>second</string>
 
    <!-- optional: use state machine with id instead of empty string -->
    <string name='stateMachine'>second</string>
 
    <!--
    optional: set controller mapping instead of using default mapping.
    keys are the controller names and value the LocomotionAttribute constant names.
    the listing below is equivalent to the default controller mapping.
    -->
    <map name='controllerMapping'>
      <string key='idle'>elapsedTime</string>
      <string key='look.vertical'>lookVertical</string>
      <string key='look.horizontal'>lookHorizontal</string>
      <string key='turn.inPlace'>timeTurnIP</string>
      <string key='turn.velocity'>turningSpeed</string>
      <string key='stance'>stance</string>
      <string key='move.walk'>displacement</string>
      <string key='move.run'>displacement</string>
      <string key='move.velocity'>relativeMovingSpeed</string>
      <string key='tilt.vertical'>tiltVertical</string>
      <string key='tilt.horizontal'>tiltHorizontal</string>
      <string key='tilt.offset'>tiltOffset</string>
      <string key='interaction'>elapsedTime</string>
    </map>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <map name='.animators'>
      <string key='default'>default.deanimator</string>
      <string key='sitting'>sitting.deanimator</string>
      <string key='flying'>flying.deanimator</string>
    </map>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorActorAnimated' id='second'>
    ...
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_actoranimated.txt · Last modified: 2025/05/04 13:43 by dragonlord