{{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]] >> **ECBehaviorVRHandLocomotion**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorVRHandLocomotion ======
This behavior is designed to be used with [[behavior_vrhand|ECBehaviorVRHand]] for which ''isUsingHandInteraction()'' returns true.
Using hands only (or hand interaction) controllers there is no way to use sticks to move or turn the actor. This behavior simulates stick type movement by tracking hand position. The user begins moving and turning by looking at his hand and touching an application defined finger to the thumb, typically the middle finger. The index is usually a bad choice since VR runtimes tend to intercept this touch event for special system handling. The hand location relative to the HMD at the time of touching is stored as origin. While still touching the thumb the user can then move the hand left, right, forward, backwards, up and down. This is like if the user is moving the tip of an imaginary stick. Each movement direction is assigned a ''Command'' of this the analog value is set from the distance from the origin. Left/right is the X axis, up/down the Y axis and forward/backward the Z axis. Furthermore button press events are simulated on the same commands if the value is larger than 75% away from the origin. There is a dead-zone near the stored origin to avoid unintentional turning or moving. Furthermore the input is not linear from the dead zone border to the input range. This allows for easier input of small turning and movement while still being able to turn and move faster near the range.
====== Instance Counts ======
This behavior can be added twice to an element to add support for left and right hand. Use the behavior identifier to tell them apart.
====== Element Class Properties ======
This behavior adds no element class properties.
====== Behavior Tree Actions ======
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''vrHandLocomotion'' with ''vrHandLocomotion(id)''.
===== vrHandLocomotion.set =====
Set VR hand locomotion parameters.
^Parameter^Value^Description^
|enabled|''true'', ''false''|Enable hand locomotion tracking.|
|deadzone|float|Deadzone as percentage of the range. User has to move hand further from the center than the range*deadzone distance to start locomotion tracking. Value is clamped to range from 0 to 1.|
|linearity|float|Set linearity of input. Value of 0 is linear input. Values up to 1 map larger input range to small movement. Values down to -1 map larger input range to larger movement. 0.25 is the default.
Linearity is calculated like this:
^Linearity^Mapped value (x=input)^
|0|x|
|1/3|pow(x, 2)|
|2/3|pow(x, 4)|
|1|pow(x, 8)|
|-1/3|pow(x, 1/2)|
|-2/3|pow(x, 1/4)|
|-1|pow(x, 1/8)|
|
|command.profile|string|Set commands to run using a profile name.
^Profile^Commands^
|move|Set MoveLR as X axis command, MoveFB as Z axis command, and null as Y axis command|
|turn|Set LookLR as X axis command and null as Y and Z axis command|
|turnMove|Set LookLR as X axis command and MoveFB as Z axis command, and null as Y axis command|
|clear|Set all commands to ''null''|
|
|command.x|string|Set named command for both positive and negative X axis or empty to clear|
|command.x.positive|string|Set named command for positive X axis or empty to clear|
|command.x.negative|string|Set named command for positive X axis or empty to clear|
|command.y|string|Set named command for both positive and negative Y axis or empty to clear|
|command.y.positive|string|Set named command for positive Y axis or empty to clear|
|command.y.negative|string|Set named command for positive Y axis or empty to clear|
|command.z|string|Set named command for both positive and negative Z axis or empty to clear|
|command.z.positive|string|Set named command for positive Z axis or empty to clear|
|command.z.negative|string|Set named command for positive Z axis or empty to clear|
This is an example of using this action:
turn
===== vrHandLocomotion.check =====
Check one or more VR hand locomotion parameters. Action succeeds if all parameter value matches their respective VR hand locomotion parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a VR hand locomotion parameter matches (or not).
Input values are in the range from -1 to 1. Deadzone is not included hence a value of 0 refers to any hand position inside the deadzone area. Positive X axis is to the right, positive Y axis up and positive Z axis forward.
Not set command matches empty string.
^Parameter^Value^Description^
|enabled|''true'', ''false''|Hand locomotion is enabled|
|running|''true'', ''false''|Hand tracking is running|
|input.x.value.less|float|X axis input value is less than value (range -1 to 1)|
|input.x.value.greater|float|X axis input value is greater than value (range -1 to 1)|
|input.y.value.less|float|Y axis input value is less than value (range -1 to 1)|
|input.y.value.greater|float|Y axis input value is greater than value (range -1 to 1)|
|input.z.value.less|float|Z axis input value is less than value (range -1 to 1)|
|input.z.value.greater|float|Z axis input value is greater than value (range -1 to 1)|
|command.x.positive|string|Name of positive X axis command matches value|
|command.x.positive.not|string|Name of positive X axis command matches not value|
|command.x.negative|string|Name of negative X axis command matches value|
|command.x.negative.not|string|Name of negative X axis command matches not value|
|command.y.positive|string|Name of positive Y axis command matches value|
|command.y.positive.not|string|Name of positive Y axis command matches not value|
|command.y.negative|string|Name of negative Y axis command matches value|
|command.y.negative.not|string|Name of negative Y axis command matches not value|
|command.z.positive|string|Name of positive Z axis command matches value|
|command.z.positive.not|string|Name of positive Z axis command matches not value|
|command.z.negative|string|Name of negative Z axis command matches value|
|command.z.negative.not|string|Name of negative Z axis command matches not value|
|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
0.5
====== Behavior Tree Conditions ======
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''vrHandLocomotion'' with ''vrHandLocomotion(id)''.
===== vrHandLocomotion.check =====
Check one or more VR hand point-at parameters. Conditions returns true if all parameter value match their respective VR hand point-at parameter. This condition is typically used to run an action or sequence of actions as long as VR hand point-at conditions are true.
Input values are in the range from -1 to 1. Deadzone is not included hence a value of 0 refers to any hand position inside the deadzone area. Positive X axis is to the right, positive Y axis up and positive Z axis forward.
Not set command matches empty string.
^Parameter^Value^Description^
|vrHandLocomotion.enabled|''true'', ''false''|Hand locomotion is enabled|
|vrHandLocomotion.running|''true'', ''false''|Hand tracking is running|
|vrHandLocomotion.input.x.value.less|float|X axis input value is less than value (range -1 to 1)|
|vrHandLocomotion.input.x.value.greater|float|X axis input value is greater than value (range -1 to 1)|
|vrHandLocomotion.input.y.value.less|float|Y axis input value is less than value (range -1 to 1)|
|vrHandLocomotion.input.y.value.greater|float|Y axis input value is greater than value (range -1 to 1)|
|vrHandLocomotion.input.z.value.less|float|Z axis input value is less than value (range -1 to 1)|
|vrHandLocomotion.input.z.value.greater|float|Z axis input value is greater than value (range -1 to 1)|
|vrHandLocomotion.command.x.positive|string|Name of positive X axis command matches value|
|vrHandLocomotion.command.x.positive.not|string|Name of positive X axis command matches not value|
|vrHandLocomotion.command.x.negative|string|Name of negative X axis command matches value|
|vrHandLocomotion.command.x.negative.not|string|Name of negative X axis command matches not value|
|vrHandLocomotion.command.y.positive|string|Name of positive Y axis command matches value|
|vrHandLocomotion.command.y.positive.not|string|Name of positive Y axis command matches not value|
|vrHandLocomotion.command.y.negative|string|Name of negative Y axis command matches value|
|vrHandLocomotion.command.y.negative.not|string|Name of negative Y axis command matches not value|
|vrHandLocomotion.command.z.positive|string|Name of positive Z axis command matches value|
|vrHandLocomotion.command.z.positive.not|string|Name of positive Z axis command matches not value|
|vrHandLocomotion.command.z.negative|string|Name of negative Z axis command matches value|
|vrHandLocomotion.command.z.negative.not|string|Name of negative Z axis command matches not value|
This is an example of using this condition:
true
0.5
vrHandLocomotion(right).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. If behavior has non-empty identifier replace ''vrHandLocomotion'' with ''vrHandLocomotion(id)''.
===== vrHandLocomotion.enabled =====
VR hand locomotion has been enabled.
===== vrHandLocomotion.disabled =====
VR hand locomotion has been disabled.
===== vrHandLocomotion.start =====
Input tracking has been started.
===== vrHandLocomotion.stop =====
Input tracking has been stopped.
====== Required Behaviors ======
* [[behavior_vrhand|ECBehaviorVRHand]]
* [[behavior_playercontrollable|ECBehaviorPlayerControllable]]
====== 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 require element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorVRHandLocomotion.html,ECBehaviorVRHandLocomotion~@#.
Since DragonScript Module Version ''1.28''
====== Use Cases ======
* Allow player to move and turn using hand interaction only (no controller in hand)
====== Element Class Example ======
The following example creates an element class with support for hand locomotion:
class MyElement extends BehaviorElementClass
public var ECBehaviorPlayerControllable playerControllable
public var ECBehaviorVRPlayspace vrPlayspace
public var ECBehaviorVRHand vrHandRight
public var ECBehaviorVRHand vrHandLeft
public var ECBehaviorVRHandLocomotion vrRightHandLocomotion
public var ECBehaviorVRHandLocomotion vrLeftHandLocomotion
public func new()
// Create player controllable
playerControllable = ECBehaviorPlayerControllablenew(this)
// Create playspace
vrPlayspace = ECBehaviorVRPlayspace.new(this)
// Create hand controllers. The InputDeviceType indicates what device type
// to monitor. vrRightHand and vrLeftHand can exist only once
vrHandRight = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrRightHand, "right")
vrHandLeft = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrLeftHand, "left")
// Create hand locomotion behavior for each hand
vrRightHandLocomotion = ECBehaviorVRHandLocomotion.new(this, vrRightHand, playerControllable, "right")
vrLeftHandLocomotion = ECBehaviorVRHandLocomotion.new(this, vrLeftHand, playerControllable, "left")
end
end
The #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BaseVRActorClass.html,BaseVRActorClass~@# provides full VR support including ECBehaviorVRHandLocomotion for both hands.
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
right
default
default
default
value
...
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]: ExampleVR project.