User Tools

Site Tools


dragengine:modules:dragonscript:behavior_vrbody

ECBehaviorVRBody

Behavior in action

Behavior element behavior adding VR Body tracking support to actor. This behavior tracks a body tracker input device providing bone pose data for the upper or full body of the user. A body rig describing the skeleton is optionally provided by the tracking device. The behavior uses this rig to do automatic retargeteting of tracked pose to the actor model.

This behavior requires ECBehaviorActorAnimated to obtain the component to animate. The behavior registers itself as listener to ECBehaviorActorAnimated and is applied after animators defined by behaviors from BaseActorClass. In particular this applies the tracked poses after the base animation and conversation system animations. Additional animations can then be applied on top of the body tracked animation using other behaviors.

This behavior applies inverse kinematics to arms after applying the pose. This componesates positional differences due to differing rigs and ensures the hands are located where the ECBehaviorVRHand would be if body tracking is not used.

This behavior applies only body bone poses including the hand wrists. Palm and finger poses are applied by ECBehaviorVRHandPose to avoid conflicts and simplify the implementation.

Instance Counts

This behavior can be added only once to an element.

Element Class Properties

Element class properties have the prefix vrBody..

onlyRotation

Apply only orientation of tracked bones or position and orientation. Applying only the the orientation of tracked bones is recommended. The behavior applies inverse kinematics to arms to compensate for positional differences.

  • Full name: vrBody.onlyRotation
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass):
    <boolean name='vrBody.onlyRotation'>false</boolean>

enableLowerBody

Applies lower body bone poses (legs and feet) if supported by the input device provides full body tracking. Upper body bones (spine, chest, arms, neck, head) are always applied.

  • Full name: vrBody.enableLowerBody
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass):
    <boolean name='vrBody.enableLowerBody'>false</boolean>

boneOrigin

Name of the origin bone in the actor rig. This bone is used as the reference point for aligning the tracked body pose with the actor model. Set to empty string to not use an origin bone.

  • Full name: vrBody.boneOrigin
  • Type: string
  • Default Value: “origin”
  • Example (*.deeclass):
    <string name='vrBody.boneOrigin'>hips</string>

Upper Body Bone Names

These properties define the names of upper body bones in the actor rig. Set to empty string if not present or not desired to be animated.

PropertyDefault ValueTracked Bone
vrBody.boneHipshipsHips
vrBody.boneSpineLowerspineLowerLower spine
vrBody.boneSpineMiddlespineMiddleMiddle spine
vrBody.boneSpineUpperspineUpperUpper spine
vrBody.boneChestchestChest
vrBody.boneNeckneckNeck
vrBody.boneHeadheadHead
vrBody.boneLeftShouldershoulder.lLeft shoulder
vrBody.boneLeftScapulascapula.lLeft scapula
vrBody.boneLeftArmUpperarmUpper.lLeft upper arm
vrBody.boneLeftArmLowerarmLower.lLeft lower arm
vrBody.boneLeftHandWristTwistwristTwist.lLeft wrist twist
vrBody.boneLeftHandWristwrist.lLeft wrist
vrBody.boneRightShouldershoulder.rRight shoulder
vrBody.boneRightScapulascapula.rRight scapula
vrBody.boneRightArmUpperarmUpper.rRight upper arm
vrBody.boneRightArmLowerarmLower.rRight lower arm
vrBody.boneRightHandWristTwistwristTwist.rRight wrist twist
vrBody.boneRightHandWristwrist.rRight wrist

Example (*.deeclass):

<string name='vrBody.boneHips'>waist</string>
<string name='vrBody.boneLeftHandWrist'>hand.l</string>

Lower Body Bone Names

These properties define the names of lower body bones in the actor rig. These are only used if the input device provides full body tracking and vrBody.enableLowerBody is set to true. Set the property to empty string if bone is not present or not desired to be animated.

PropertyDefault ValueTracked Bone
vrBody.boneLeftUpperLegupperLeg.lLeft upper leg
vrBody.boneLeftLowerLeglowerLeg.lLeft lower leg
vrBody.boneLeftFootAnkleTwistfootAnkleTwist.lLeft ankle twist
vrBody.boneLeftFootAnklefootAnkle.lLeft ankle
vrBody.boneLeftFootSubtalarfootSubtalar.lLeft foot subtalar
vrBody.boneLeftFootTransversefootTransverse.lLeft foot transverse
vrBody.boneLeftFootBallfootBall.lLeft foot ball
vrBody.boneRightUpperLegupperLeg.rRight upper leg
vrBody.boneRightLowerLeglowerLeg.rRight lower leg
vrBody.boneRightFootAnkleTwistfootAnkleTwist.rRight ankle twist
vrBody.boneRightFootAnklefootAnkle.rRight ankle
vrBody.boneRightFootSubtalarfootSubtalar.rRight foot subtalar
vrBody.boneRightFootTransversefootTransverse.rRight foot transverse
vrBody.boneRightFootBallfootBall.rRight foot ball

Example (*.deeclass):

<string name='vrBody.boneLeftUpperLeg'>leg.u.l</string>
<string name='vrBody.boneLeftFootAnkle'>foot.l</string>

Events

inputDeviceAttached

Input device attached and ready to use.

inputDeviceDetached

Input device detached and no more usable.

bodyRigChanged

Bone rig skeleton provided by the input device changed. Happens when the input device recalibrates the user. Bones are automatically retargeted to the new body rig.

Behavior Tree Actions

This behavior adds these behavior tree actions if a behavior tree is present.

vrBody.check

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

ParameterValueDescription
attachedtrue, falseBody tracker is attached
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='vrBody.check'>
    <parameter name='attached'>true</parameter>
  </action>
  <!-- actions here run only if body tracker is attached -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if a behavior tree is present.

vrBody.check

Check one or more VR body parameters. Condition returns true if all parameter values match their respective VR body parameter. This condition is typically used to run an action or sequence of actions as long as VR body conditions are true.

ParameterValueDescription
vrBody.attachedtrue, falseBody tracker is attached

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='vrBody.attached'>true</parameter>
  <condition>vrBody.check</condition>
</action>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends these state machine events.

vrBody.attached

Input device has been attached.

vrBody.detached

Input device has been detached.

vrBody.rigChanged

Body rig of the input device changed. This happens when the input device recalibrates the user.

Required Behaviors

Optional Behaviors

Persistency

This behavior does not use persistency.

API Documentation

ECBehaviorVRBody.

Since DragonScript Module Version 1.31

Use Cases

  • Animate actor body using full body or upper body VR tracking for VR actors.

Element Class Example

The following example creates an element class with VR body tracking.

class MyElement extends BehaviorElementClass
  func new()
    // Add basic components required for player body
    var ECBehaviorComponent component = ECBehaviorComponent.new(this, null)
    var ECBehaviorCollider collider = ECBehaviorCollider.new(this, component)
    var ECBehaviorColliderAI colliderAI = ECBehaviorColliderAI.new(this, collider)
    var ECBehaviorLocomotion locomotion = ECBehaviorLocomotion.new(this, colliderAI)
    
    // Add actor animated allowing to animate player body
    var ECBehaviorActorAnimated actorAnimated = ECBehaviorActorAnimated.new(this, component, locomotion)
    
    // Add VR Playspace behavior. Base behavior required by all VR behaviors
    var ECBehaviorVRPlayspace vrPlayspace = ECBehaviorVRPlayspace.new(this)
    
    // Add VR HMD behavior. With this behavior present VRPlayerControlledActorCameraDirector
    // can attach the HMD to the in-game camera
    ECBehaviorVRHMD.new(this, vrPlayspace)
    
    // Add body tracking
    ECBehaviorVRBody.new(this, vrPlayspace, actorAnimated)
    
    // Add left and right hand behaviors. Add them after the body behavior to apply them afterwards
    ...
  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='ECBehaviorLocomotion'/>
  <behavior type='ECBehaviorActorAnimated'/>
  <behavior type='ECBehaviorVRPlayspace'/>
  <behavior type='ECBehaviorVRHMD'/>
 
  <behavior type='ECBehaviorVRBody'>
    <!-- optional: use ECBehaviorActorAnimated with identifier instead of default one. -->
    <string name='actorAnimated'>identifier</string>
 
    <!-- optional: use BaseGameApp binding manager. game can add more supported values.
                   default is 'default' -->
    <string name='bindingManager'>default</string>
 
    <!-- optional: add behavior trees. default adds all behavior trees. -->
    <list name='behaviorTrees'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
 
    <!-- optional: add state machines. default adds all state machines. -->
    <list name='stateMachines'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <boolean name='.onlyRotation'>false</boolean>
    <boolean name='.enableLowerBody'>false</boolean>
 
    <!-- optional: override bone names if character rig uses different naming -->
    <string name='.boneHips'>waist</string>
    <string name='.boneLeftHandWrist'>hand.l</string>
    <string name='.boneRightHandWrist'>hand.r</string>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_vrbody.txt · Last modified: 2026/03/26 02:03 by dragonlord