{{tag>dragonscript behavior}}
[[: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]] >> **ECBehaviorVRBody**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorVRBody ======
{{youtube>oQ4iZvgfyGc?medium}}
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 [[behavior_actoranimated|ECBehaviorActorAnimated]] to obtain the component to animate. The behavior registers itself as listener to [[behavior_actoranimated|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 [[behavior_vrhand|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 [[behavior_vrhandpose|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): false
===== 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): false
===== 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): hips
===== 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.
^Property^Default Value^Tracked Bone^
|''vrBody.boneHips''|''hips''|Hips|
|''vrBody.boneSpineLower''|''spineLower''|Lower spine|
|''vrBody.boneSpineMiddle''|''spineMiddle''|Middle spine|
|''vrBody.boneSpineUpper''|''spineUpper''|Upper spine|
|''vrBody.boneChest''|''chest''|Chest|
|''vrBody.boneNeck''|''neck''|Neck|
|''vrBody.boneHead''|''head''|Head|
|''vrBody.boneLeftShoulder''|''shoulder.l''|Left shoulder|
|''vrBody.boneLeftScapula''|''scapula.l''|Left scapula|
|''vrBody.boneLeftArmUpper''|''armUpper.l''|Left upper arm|
|''vrBody.boneLeftArmLower''|''armLower.l''|Left lower arm|
|''vrBody.boneLeftHandWristTwist''|''wristTwist.l''|Left wrist twist|
|''vrBody.boneLeftHandWrist''|''wrist.l''|Left wrist|
|''vrBody.boneRightShoulder''|''shoulder.r''|Right shoulder|
|''vrBody.boneRightScapula''|''scapula.r''|Right scapula|
|''vrBody.boneRightArmUpper''|''armUpper.r''|Right upper arm|
|''vrBody.boneRightArmLower''|''armLower.r''|Right lower arm|
|''vrBody.boneRightHandWristTwist''|''wristTwist.r''|Right wrist twist|
|''vrBody.boneRightHandWrist''|''wrist.r''|Right wrist|
Example (*.deeclass):
waist
hand.l
===== 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.
^Property^Default Value^Tracked Bone^
|''vrBody.boneLeftUpperLeg''|''upperLeg.l''|Left upper leg|
|''vrBody.boneLeftLowerLeg''|''lowerLeg.l''|Left lower leg|
|''vrBody.boneLeftFootAnkleTwist''|''footAnkleTwist.l''|Left ankle twist|
|''vrBody.boneLeftFootAnkle''|''footAnkle.l''|Left ankle|
|''vrBody.boneLeftFootSubtalar''|''footSubtalar.l''|Left foot subtalar|
|''vrBody.boneLeftFootTransverse''|''footTransverse.l''|Left foot transverse|
|''vrBody.boneLeftFootBall''|''footBall.l''|Left foot ball|
|''vrBody.boneRightUpperLeg''|''upperLeg.r''|Right upper leg|
|''vrBody.boneRightLowerLeg''|''lowerLeg.r''|Right lower leg|
|''vrBody.boneRightFootAnkleTwist''|''footAnkleTwist.r''|Right ankle twist|
|''vrBody.boneRightFootAnkle''|''footAnkle.r''|Right ankle|
|''vrBody.boneRightFootSubtalar''|''footSubtalar.r''|Right foot subtalar|
|''vrBody.boneRightFootTransverse''|''footTransverse.r''|Right foot transverse|
|''vrBody.boneRightFootBall''|''footBall.r''|Right foot ball|
Example (*.deeclass):
leg.u.l
foot.l
====== 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).
^Parameter^Value^Description^
|attached|''true'', ''false''|Body 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:
true
====== 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.
^Parameter^Value^Description^
|vrBody.attached|''true'', ''false''|Body tracker is attached|
This is an example of using this condition:
true
vrBody.check
====== 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.
===== 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 ======
* [[behavior_vrplayspace|ECBehaviorVRPlayspace]]
* [[behavior_actoranimated|ECBehaviorActorAnimated]]
====== 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 ======
This behavior does not use persistency.
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorVRBody.html,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:
identifier
default
default
default
false
false
waist
hand.l
hand.r
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]: ExampleVR project.
* [[https://github.com/LordOfDragons/dragengine/blob/master/src/modules/scripting/dragonscript/scripts/scenery/actor/BaseVRActorClass.ds|BaseVRActorClass]]: Base class for VR actors