User Tools

Site Tools


dragengine:modules:dragonscript:behavior_animated

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dragengine:modules:dragonscript:behavior_animated [2025/03/12 14:43] – [ECBehaviorAnimated] dragonlorddragengine:modules:dragonscript:behavior_animated [2025/05/04 13:45] (current) – [animated.check] dragonlord
Line 1: Line 1:
 {{tag>dragonscript behavior}} {{tag>dragonscript behavior}}
 <WRAP youarehere> <WRAP youarehere>
-[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorAnimated**+[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorAnimated**
 </WRAP> </WRAP>
  
Line 108: Line 108:
  
 A typical usage pattern for such behaviors is to locate the animator controller to update during construction time and to manipulated the controllers inside updateControllers(). A typical usage pattern for such behaviors is to locate the animator controller to update during construction time and to manipulated the controllers inside updateControllers().
 +
 See [[#element_class_example|Element Class Example]] for example code. See [[#element_class_example|Element Class Example]] for example code.
  
Line 127: Line 128:
  
 Animation has been applied. Animation has been applied.
 +
 +====== Behavior Tree Actions ======
 +
 +This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''animated'' with ''animated(id)''.
 +
 +===== animated.set =====
 +
 +Set one or more animated parameters.
 +
 +^Parameter^Value^Description^
 +|playing|''true'', ''false''|Set if animation is playing|
 +|time|float|Set animation time in seconds|
 +|time.relative|float|Set animation time in percentage from 0 (begin) to 1 (end)|
 +
 +This is an example of using this action:
 +<code xml>
 +<action name='animated.set'>
 +  <parameter name='playing'>true</parameter>
 +</action>
 +</code>
 +
 +===== animated.check =====
 +
 +Check one or more animated parameters. Action succeeds if all parameter value matches their respective animated parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a animated parameter matches (or not).
 +
 +^Parameter^Value^Description^
 +|playing|''true'', ''false''|Animation is playing|
 +|time.less|float|Animation time is less than value in seconds|
 +|time.greater|float|Animation time is greater than value in seconds|
 +|time.relative.less|float|Relative animation time (0=begin, 1=end) is less than value in seconds|
 +|time.relative.greater|float|Relative animation time (0=begin, 1=end) is greater than value in seconds|
 +|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:
 +<code xml>
 +<sequence>
 +  <action name='animated.check'>
 +    <parameter name='playing'>true</parameter>
 +    <parameter name='time.less'>3</parameter>
 +  </action>
 +  <!-- actions here run only if animation is playing and animation time is less than 3 seconds -->
 +</sequence>
 +</code>
 +
 +====== Behavior Tree Conditions ======
 +
 +This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''animated'' with ''animated(id)''.
 +
 +===== animated.check =====
 +
 +Check one or more animated parameters. Conditions returns true if all parameter value match their respective animated parameter. This condition is typically used to run an action or sequence of actions as long as animated conditions are true.
 +
 +^Parameter^Value^Description^
 +|animated.playing|''true'', ''false''|Animation is playing|
 +|animated.time.less|float|Animation time is less than value in seconds|
 +|animated.time.greater|float|Animation time is greater than value in seconds|
 +|animated.time.relative.less|float|Relative animation time (0=begin, 1=end) is less than value in seconds|
 +|animated.time.relative.greater|float|Relative animation time (0=begin, 1=end) is greater than value in seconds|
 +
 +This is an example of using this condition:
 +<code xml>
 +<action name='myAction' id='doing something'>
 +  <parameter name='animated.playing'>true</parameter>
 +  <parameter name='animated.time.less'>3</parameter>
 +  <condition>animated.check</condition>
 +</action>
 +</code>
 +
 +====== State Machine Actions ======
 +
 +Same as [[#behavior_tree_actions|Behavior Tree Actions]].
 +
 +====== State Machine Conditions ======
 +
 +Same as [[#behavior_tree_conditions|Behavior Tree Conditions]].
 +
 +====== State Machine Events ======
 +
 +This behavior sends these state machine events. If behavior has non-empty identifier replace ''animated'' with ''animated(id)''.
 +
 +===== animated.startPlaying =====
 +
 +Start playing back.
 +
 +===== animated.stopPlaying =====
 +
 +Stop playing.
  
 ====== Required Behaviors ====== ====== Required Behaviors ======
  
-This behavior requires these other behaviors: 
   * [[behavior_component|ECBehaviorComponent]]   * [[behavior_component|ECBehaviorComponent]]
  
 ====== Optional Behaviors ====== ====== Optional Behaviors ======
  
-This behavior does not support optional behaviors+  * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use
 +  * [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine.
 ====== Persistency ====== ====== Persistency ======
  
Line 163: Line 250:
     component = ECBehaviorComponent.new(this, null)     component = ECBehaviorComponent.new(this, null)
     animated = ECBehaviorAnimated.new(this, component)     animated = ECBehaviorAnimated.new(this, component)
 +  end
 +end
 +</code>
 +
 +Example of using listeners.
 +
 +<code>
 +class MyListener extends ECBehaviorInstance.DefaultListener
 +  var AnimatorController pController
 +  
 +  func new(ECBehaviorAnimated behavior)
 +    pController = behavior.getAnimatorInstance().getControllerNamed("special controller")
 +  end
 +  
 +  func void updateControllers(Instance instance, float elapsed)
 +    pController.increment(elapsed)
   end   end
 end end
Line 182: Line 285:
                    default is 'default' -->                    default is 'default' -->
     <string name='triggerTable'>default</string>     <string name='triggerTable'>default</string>
 +    
 +    <!-- optional: identifier of ECBehaviorTriggered to synchronize with or empty
 +                   string to not synchronize. default is empty string. -->
 +    <string name='trigger.synchronize'>other</string>
          
     <!-- optional: use named controller instead of first controller. default is empty string -->     <!-- optional: use named controller instead of first controller. default is empty string -->
     <string name='controllerName'>playback</string>     <string name='controllerName'>playback</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>
          
     <!-- set element properties. omit property prefix if used inside behavior tag -->     <!-- set element properties. omit property prefix if used inside behavior tag -->
dragengine/modules/dragonscript/behavior_animated.1741790626.txt.gz · Last modified: 2025/03/12 14:43 by dragonlord