User Tools

Site Tools


dragengine:modules:dragonscript:behavior_actorik

Differences

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

Link to this comparison view

Next revision
Previous revision
dragengine:modules:dragonscript:behavior_actorik [2020/06/01 11:28] – created dragonlorddragengine:modules:dragonscript:behavior_actorik [2025/03/13 17:08] (current) 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]] >> **ECBehaviorActorIK**+[[: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]] >> **ECBehaviorActorIK**
 </WRAP> </WRAP>
  
Line 16: Line 16:
 [[behavior_component|ECBehaviorComponent]]. [[behavior_component|ECBehaviorComponent]].
  
-The behavior supports controllers to input IK information to the animator.+The behavior supports these controllers to input IK information to the animator.
  
-The **IK Position Controller** is used to set position of the target relative to the component assigned to the animator. The position is assigned as //vector value//.+The **IK Position Controller** is used to set position of the target relative to the component assigned to the animator. The position is assigned as '//'vector value//.
  
 The **IK Rotation Controller** is used to set orientation of the target relative to the component assigned to the animator. The orientation is assigned as //vector value//. The **IK Rotation Controller** is used to set orientation of the target relative to the component assigned to the animator. The orientation is assigned as //vector value//.
  
-The **IK Height Controller** is used to set the height of the target above the ground. This is the same value as //position.getY()// but assigned as single //value//. This controller+The **IK Height Controller** is used to set the height of the target above the ground. This is the same value as ''position.getY()'' but assigned as single //value//. This controller
 allows to fine tune animators to different target heights above ground. To get the best results you usually have to use an animation for reaching at objects in upright and crouched position. Using this controller you can blend between such animations. allows to fine tune animators to different target heights above ground. To get the best results you usually have to use an animation for reaching at objects in upright and crouched position. Using this controller you can blend between such animations.
 +
 +The **IK Pan Controller** is used to set the left-right position of the target. This is the same value as ''position.getX()'' but assigned as single //value//.
 +
 +The **IK Distance Controller** is used to set the forward-backward position of the target. This is the same value as ''position.getZ()'' but assigned as single //value//.
 +
 +The **IK Azimuth Controller** is used to set the left-right rotation of the target. This is the same value as ''rotation.getY()'' but assigned as single //value//.
 +
 +The **IK Elevation Controller** is used to set the up-down rotation of the target. This is the same value as ''rotation.getX()'' but assigned as single //value//.
  
 ====== Instance Counts ====== ====== Instance Counts ======
Line 34: Line 42:
  
 ===== controllerIKPosition ===== ===== controllerIKPosition =====
-Name of the controller to assign IK Position to using //vector value//. If the controller is not found it is ignored.+Name of the controller to assign IK position to using //vector value//. If the controller is not found it is ignored.
   * Full name: "actorIK.controllerIKPosition" or "actorIK(id).controllerIKPosition"   * Full name: "actorIK.controllerIKPosition" or "actorIK(id).controllerIKPosition"
   * Type string   * Type string
-  * Default Value //ik.position//+  * Default Value ''ik.position''
   * Example (*.deeclass) <code xml><string name='actorIK.controllerIKPosition'>ik.position</string></code>   * Example (*.deeclass) <code xml><string name='actorIK.controllerIKPosition'>ik.position</string></code>
  
 ===== controllerIKRotation ===== ===== controllerIKRotation =====
-Name of the controller to assign IK Rotatio to using //vector value//. If the controller is not found it is ignored.+Name of the controller to assign IK rotatio to using //vector value//. If the controller is not found it is ignored.
   * Full name: "actorIK.controllerIKRotation" or "actorIK(id).controllerIKRotation"   * Full name: "actorIK.controllerIKRotation" or "actorIK(id).controllerIKRotation"
   * Type string   * Type string
-  * Default Value //ik.rotation//+  * Default Value ''ik.rotation''
   * Example (*.deeclass) <code xml><string name='actorIK.controllerIKRotation'>ik.rotation</string></code>   * Example (*.deeclass) <code xml><string name='actorIK.controllerIKRotation'>ik.rotation</string></code>
  
 ===== controllerIKHeight ===== ===== controllerIKHeight =====
-Name of the controller to assign IK Height to using //value//. If the controller is not found it is ignored.+Name of the controller to assign IK height (Y axis position) to using //value//. If the controller is not found it is ignored.
   * Full name: "actorIK.controllerIKHeight" or "actorIK(id).controllerIKHeight"   * Full name: "actorIK.controllerIKHeight" or "actorIK(id).controllerIKHeight"
   * Type string   * Type string
-  * Default Value //ik.height//+  * Default Value ''ik.height''
   * Example (*.deeclass) <code xml><string name='actorIK.controllerIKHeight'>ik.height</string></code>   * Example (*.deeclass) <code xml><string name='actorIK.controllerIKHeight'>ik.height</string></code>
 +
 +===== controllerIKPan =====
 +Name of the controller to assign IK pan (X axis position) to using //value//. If the controller is not found it is ignored.
 +  * Full name: "actorIK.controllerIKPan" or "actorIK(id).controllerIKPan"
 +  * Type string
 +  * Default Value ''ik.pan''
 +  * Example (*.deeclass) <code xml><string name='actorIK.controllerIKPan'>ik.pan</string></code>
 +
 +===== controllerIKDistance =====
 +Name of the controller to assign IK distance (Z axis position) to using //value//. If the controller is not found it is ignored.
 +  * Full name: "actorIK.controllerIKDistance" or "actorIK(id).controllerIKDistance"
 +  * Type string
 +  * Default Value ''ik.distance''
 +  * Example (*.deeclass) <code xml><string name='actorIK.controllerIKDistance'>ik.distance</string></code>
 +
 +===== controllerIKAzimuth =====
 +Name of the controller to assign IK azimuth (Y axis rotation) to using //value//. If the controller is not found it is ignored.
 +  * Full name: "actorIK.controllerIKAzimuth" or "actorIK(id).controllerIKAzimuth"
 +  * Type string
 +  * Default Value ''ik.azimuth''
 +  * Example (*.deeclass) <code xml><string name='actorIK.controllerIKAzimuth'>ik.azimuth</string></code>
 +
 +===== controllerIKElevation =====
 +Name of the controller to assign IK elevation (X axis rotation) to using //value//. If the controller is not found it is ignored.
 +  * Full name: "actorIK.controllerIKElevation" or "actorIK(id).controllerIKElevation"
 +  * Type string
 +  * Default Value ''ik.elevation''
 +  * Example (*.deeclass) <code xml><string name='actorIK.controllerIKElevation'>ik.elevation</string></code>
 +
 +====== Events ======
 +
 +This behavior has no events.
  
 ====== Required Behaviors ====== ====== Required Behaviors ======
Line 61: Line 101:
  
 ====== Persistency ====== ====== Persistency ======
-This behavior supports persistencyThese parameters are persisted: +This behavior does support element class to be persistable (setPersistable).
-  * Enabled +
-  * Target Matrix +
-  * Target Element +
-  * Target Bone+
  
 ====== API Documentation ====== ====== API Documentation ======
-[[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorActorIK.html|ECBehaviorActorIK]].+#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorActorIK.html,ECBehaviorActorIK~@#.
  
-Since DragonScript Module Version **1.2**+Since DragonScript Module Version ''1.2''
  
 ====== Use Cases ====== ====== Use Cases ======
Line 78: Line 114:
  
 <code> <code>
-// example class applying IK to one body group+pin Dragengine.Scenery 
 class ObjectElementClass extends BaseActorClass class ObjectElementClass extends BaseActorClass
    public var ECBehaviorActorIK actorIK    public var ECBehaviorActorIK actorIK
Line 94: Line 131:
 end end
  
-// example class applying IK to two body groups at the same time if desired +class ActorActionIK extends BAAFirstPerson 
-class ObjectElement2Class extends BaseActorClass+   public var ECBehaviorActorIK.Instance actorIK 
 +    
 +   public func new() 
 +   end 
 +    
 +   // store the behavior so we can use it 
 +   protected func void initBehaviors() 
 +      super.initBehaviors() 
 +      actorIK = ECBehaviorActorIK.getInstanceIn(actor) 
 +   end 
 +    
 +   // enable IK while this action is assigned to an actor then disable it again. 
 +   // using disable() instead of setEnabled(false) also clears the target 
 +   public func void activate() 
 +      super.activate() 
 +      actorIK.setTarget(targetElementToTouch) 
 +      actorIK.setEnabled(true) 
 +   end 
 +    
 +   public func void deactivate() 
 +      actorIK.disable() 
 +      super.deactivate() 
 +   end 
 +end 
 +</code> 
 + 
 +Example class applying IK to two body groups at the same time if desired
 +<code> 
 +pin Dragengine.Scenery 
 + 
 +class ObjectElementClass extends BaseActorClass
    public var ECBehaviorActorIK actorIKLeft    public var ECBehaviorActorIK actorIKLeft
    public var ECBehaviorActorIK actorIKRight    public var ECBehaviorActorIK actorIKRight
Line 116: Line 183:
      // using this setup actor actions can enable IK handling for each hand      // using this setup actor actions can enable IK handling for each hand
      // individually or for both at the same time      // individually or for both at the same time
 +   end
 +end
 +
 +class ActorActionIK extends BAAFirstPerson
 +   public var ECBehaviorActorIK.Instance actorIKLeft
 +   public var ECBehaviorActorIK.Instance actorIKRight
 +   
 +   public func new()
 +   end
 +   
 +   // store the behavior so we can use it
 +   protected func void initBehaviors()
 +      super.initBehaviors()
 +      actorIKLeft = ECBehaviorActorIK.getInstanceIn(actor, "left")
 +      actorIKRight = ECBehaviorActorIK.getInstanceIn(actor, "right")
 +   end
 +   
 +   // enable IK while this action is assigned to an actor then disable it again.
 +   // using disable() instead of setEnabled(false) also clears the target.
 +   // the element is facing us hence our left side is actually on the right side
 +   // from the point of view of the element. the target position is always
 +   // relative to the target element.
 +   public func void activate()
 +      super.activate()
 +      
 +      actorIKLeft.setTarget(targetElementToTouch, Vector.new(0.2, 0, 0))
 +      actorIKLeft.setEnabled(true)
 +      
 +      actorIKRight.setTarget(targetElementToTouch, Vector.new(-0.2, 0, 0))
 +      actorIKRight.setEnabled(true)
 +      
 +      // you can change target position later on using setTargetMatrix(Vector)
 +   end
 +   
 +   public func void deactivate()
 +      actorIKLeft.disable()
 +      actorIKRight.disable()
 +      super.deactivate()
    end    end
 end end
 </code> </code>
 +
 +====== Behavior Factory ======
 +
 +Using element class supporting adding behaviors the behavior can be added like this:
 +<code xml>
 +<?xml version='1.0' encoding='UTF-8'?>
 +<elementClass name='MyClass' class='GenericBehaviorElement'>
 +  <behavior type='ECBehaviorComponent'/>
 +  <behavior type='ECBehaviorCollider'/>
 +  <behavior type='ECBehaviorActorAnimated'/>
 +  
 +  <behavior type='ECBehaviorActorIK'>
 +    <!-- optional: use actor animated with id instead of empty string -->
 +    <string name='actorAnimated'>second</string>
 +    
 +    <!-- set element properties. omit property prefix if used inside behavior tag -->
 +    <string name='.controllerIKPosition'>ik.position</string>
 +    <string name='.controllerIKPan'>ik.position.x</string>
 +  </behavior>
 +  
 +  <!-- for adding multiple behaviors use unique identifiers -->
 +  <behavior type='ECBehaviorActorIK' id='second'/>
 +</elementClass>
 +</code>
 +
 +====== Live Examples ======
 +
 +  * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]
 +
dragengine/modules/dragonscript/behavior_actorik.1591010891.txt.gz · Last modified: 2020/06/01 11:28 by dragonlord