This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dragengine:modules:dragonscript:behavior_actorik [2020/06/01 11:28] – created dragonlord | dragengine:modules:dragonscript:behavior_actorik [2025/03/13 17:08] (current) – dragonlord | ||
---|---|---|---|
Line 1: | Line 1: | ||
{{tag> | {{tag> | ||
<WRAP youarehere> | <WRAP youarehere> | ||
- | [[: | + | [[: |
</ | </ | ||
Line 16: | Line 16: | ||
[[behavior_component|ECBehaviorComponent]]. | [[behavior_component|ECBehaviorComponent]]. | ||
- | The behavior supports | + | The behavior supports |
- | 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 '' |
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 '' | ||
+ | |||
+ | The **IK Distance Controller** is used to set the forward-backward position of the target. This is the same value as '' | ||
+ | |||
+ | The **IK Azimuth Controller** is used to set the left-right rotation of the target. This is the same value as '' | ||
+ | |||
+ | The **IK Elevation Controller** is used to set the up-down rotation of the target. This is the same value as '' | ||
====== Instance Counts ====== | ====== Instance Counts ====== | ||
Line 34: | Line 42: | ||
===== controllerIKPosition ===== | ===== controllerIKPosition ===== | ||
- | Name of the controller to assign IK Position | + | Name of the controller to assign IK position |
* Full name: " | * Full name: " | ||
* Type string | * Type string | ||
- | * Default Value //ik.position// | + | * Default Value '' |
* Example (*.deeclass) <code xml>< | * Example (*.deeclass) <code xml>< | ||
===== controllerIKRotation ===== | ===== controllerIKRotation ===== | ||
- | Name of the controller to assign IK Rotatio | + | Name of the controller to assign IK rotatio |
* Full name: " | * Full name: " | ||
* Type string | * Type string | ||
- | * Default Value //ik.rotation// | + | * Default Value '' |
* Example (*.deeclass) <code xml>< | * Example (*.deeclass) <code xml>< | ||
===== controllerIKHeight ===== | ===== controllerIKHeight ===== | ||
- | Name of the controller to assign IK Height | + | Name of the controller to assign IK height (Y axis position) |
* Full name: " | * Full name: " | ||
* Type string | * Type string | ||
- | * Default Value //ik.height// | + | * Default Value '' |
* Example (*.deeclass) <code xml>< | * Example (*.deeclass) <code xml>< | ||
+ | |||
+ | ===== 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: " | ||
+ | * Type string | ||
+ | * Default Value '' | ||
+ | * Example (*.deeclass) <code xml>< | ||
+ | |||
+ | ===== 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: " | ||
+ | * Type string | ||
+ | * Default Value '' | ||
+ | * Example (*.deeclass) <code xml>< | ||
+ | |||
+ | ===== 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: " | ||
+ | * Type string | ||
+ | * Default Value '' | ||
+ | * Example (*.deeclass) <code xml>< | ||
+ | |||
+ | ===== 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: " | ||
+ | * Type string | ||
+ | * Default Value '' | ||
+ | * Example (*.deeclass) <code xml>< | ||
+ | |||
+ | ====== Events ====== | ||
+ | |||
+ | This behavior has no events. | ||
====== Required Behaviors ====== | ====== Required Behaviors ====== | ||
Line 61: | Line 101: | ||
====== Persistency ====== | ====== Persistency ====== | ||
- | This behavior | + | This behavior |
- | * Enabled | + | |
- | * Target Matrix | + | |
- | * Target Element | + | |
- | * Target Bone | + | |
====== API Documentation ====== | ====== API Documentation ====== | ||
- | [[https:// | + | # |
- | Since DragonScript Module Version | + | Since DragonScript Module Version |
====== Use Cases ====== | ====== Use Cases ====== | ||
Line 78: | Line 114: | ||
< | < | ||
- | // example class applying IK to one body group | + | pin Dragengine.Scenery |
class ObjectElementClass extends BaseActorClass | class ObjectElementClass extends BaseActorClass | ||
| | ||
Line 94: | Line 131: | ||
end | end | ||
- | // example | + | class ActorActionIK extends BAAFirstPerson |
- | class ObjectElement2Class | + | |
+ | |||
+ | | ||
+ | end | ||
+ | |||
+ | // store the behavior so we can use it | ||
+ | | ||
+ | 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 | ||
+ | | ||
+ | super.activate() | ||
+ | actorIK.setTarget(targetElementToTouch) | ||
+ | actorIK.setEnabled(true) | ||
+ | end | ||
+ | |||
+ | | ||
+ | actorIK.disable() | ||
+ | super.deactivate() | ||
+ | end | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | Example | ||
+ | < | ||
+ | pin Dragengine.Scenery | ||
+ | |||
+ | class ObjectElementClass | ||
| | ||
| | ||
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 | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | end | ||
+ | |||
+ | // store the behavior so we can use it | ||
+ | | ||
+ | super.initBehaviors() | ||
+ | actorIKLeft = ECBehaviorActorIK.getInstanceIn(actor, | ||
+ | actorIKRight = 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. | ||
+ | // 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. | ||
+ | | ||
+ | super.activate() | ||
+ | | ||
+ | actorIKLeft.setTarget(targetElementToTouch, | ||
+ | actorIKLeft.setEnabled(true) | ||
+ | | ||
+ | actorIKRight.setTarget(targetElementToTouch, | ||
+ | actorIKRight.setEnabled(true) | ||
+ | | ||
+ | // you can change target position later on using setTargetMatrix(Vector) | ||
+ | end | ||
+ | |||
+ | | ||
+ | actorIKLeft.disable() | ||
+ | actorIKRight.disable() | ||
+ | super.deactivate() | ||
end | end | ||
end | end | ||
</ | </ | ||
+ | |||
+ | ====== Behavior Factory ====== | ||
+ | |||
+ | Using element class supporting adding behaviors the behavior can be added like this: | ||
+ | <code xml> | ||
+ | <?xml version=' | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | | ||
+ | < | ||
+ | <!-- optional: use actor animated with id instead of empty string --> | ||
+ | <string name=' | ||
+ | | ||
+ | <!-- set element properties. omit property prefix if used inside behavior tag --> | ||
+ | <string name=' | ||
+ | <string name=' | ||
+ | </ | ||
+ | | ||
+ | <!-- for adding multiple behaviors use unique identifiers --> | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== Live Examples ====== | ||
+ | |||
+ | * [[https:// | ||
+ |