Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorVRHandLocomotion

ECBehaviorVRHandLocomotion

This behavior is designed to be used with 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.

ParameterValueDescription
enabledtrue, falseEnable hand locomotion tracking.
deadzonefloatDeadzone 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.
linearityfloat

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:

LinearityMapped value (x=input)
0x
1/3pow(x, 2)
2/3pow(x, 4)
1pow(x, 8)
-1/3pow(x, 1/2)
-2/3pow(x, 1/4)
-1pow(x, 1/8)
command.profilestring

Set commands to run using a profile name.

ProfileCommands
moveSet MoveLR as X axis command, MoveFB as Z axis command, and null as Y axis command
turnSet LookLR as X axis command and null as Y and Z axis command
turnMoveSet LookLR as X axis command and MoveFB as Z axis command, and null as Y axis command
clearSet all commands to null
command.xstringSet named command for both positive and negative X axis or empty to clear
command.x.positivestringSet named command for positive X axis or empty to clear
command.x.negativestringSet named command for positive X axis or empty to clear
command.ystringSet named command for both positive and negative Y axis or empty to clear
command.y.positivestringSet named command for positive Y axis or empty to clear
command.y.negativestringSet named command for positive Y axis or empty to clear
command.zstringSet named command for both positive and negative Z axis or empty to clear
command.z.positivestringSet named command for positive Z axis or empty to clear
command.z.negativestringSet named command for positive Z axis or empty to clear

This is an example of using this action:

<action name='vrHandLocomotion(right).set'>
  <parameter name='command.profile'>turn</parameter>
</action>

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.

ParameterValueDescription
enabledtrue, falseHand locomotion is enabled
runningtrue, falseHand tracking is running
input.x.value.lessfloatX axis input value is less than value (range -1 to 1)
input.x.value.greaterfloatX axis input value is greater than value (range -1 to 1)
input.y.value.lessfloatY axis input value is less than value (range -1 to 1)
input.y.value.greaterfloatY axis input value is greater than value (range -1 to 1)
input.z.value.lessfloatZ axis input value is less than value (range -1 to 1)
input.z.value.greaterfloatZ axis input value is greater than value (range -1 to 1)
command.x.positivestringName of positive X axis command matches value
command.x.positive.notstringName of positive X axis command matches not value
command.x.negativestringName of negative X axis command matches value
command.x.negative.notstringName of negative X axis command matches not value
command.y.positivestringName of positive Y axis command matches value
command.y.positive.notstringName of positive Y axis command matches not value
command.y.negativestringName of negative Y axis command matches value
command.y.negative.notstringName of negative Y axis command matches not value
command.z.positivestringName of positive Z axis command matches value
command.z.positive.notstringName of positive Z axis command matches not value
command.z.negativestringName of negative Z axis command matches value
command.z.negative.notstringName 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:

<sequence>
  <action name='vrHandLocomotion(right).check'>
    <parameter name='running'>true</parameter>
    <parameter name='input.z.value.greater'>0.5</parameter>
  </action>
  <!-- actions here run only if VR hand locomotion is running and the user moved the hand at least 50% forward -->
</sequence>

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.

ParameterValueDescription
vrHandLocomotion.enabledtrue, falseHand locomotion is enabled
vrHandLocomotion.runningtrue, falseHand tracking is running
vrHandLocomotion.input.x.value.lessfloatX axis input value is less than value (range -1 to 1)
vrHandLocomotion.input.x.value.greaterfloatX axis input value is greater than value (range -1 to 1)
vrHandLocomotion.input.y.value.lessfloatY axis input value is less than value (range -1 to 1)
vrHandLocomotion.input.y.value.greaterfloatY axis input value is greater than value (range -1 to 1)
vrHandLocomotion.input.z.value.lessfloatZ axis input value is less than value (range -1 to 1)
vrHandLocomotion.input.z.value.greaterfloatZ axis input value is greater than value (range -1 to 1)
vrHandLocomotion.command.x.positivestringName of positive X axis command matches value
vrHandLocomotion.command.x.positive.notstringName of positive X axis command matches not value
vrHandLocomotion.command.x.negativestringName of negative X axis command matches value
vrHandLocomotion.command.x.negative.notstringName of negative X axis command matches not value
vrHandLocomotion.command.y.positivestringName of positive Y axis command matches value
vrHandLocomotion.command.y.positive.notstringName of positive Y axis command matches not value
vrHandLocomotion.command.y.negativestringName of negative Y axis command matches value
vrHandLocomotion.command.y.negative.notstringName of negative Y axis command matches not value
vrHandLocomotion.command.z.positivestringName of positive Z axis command matches value
vrHandLocomotion.command.z.positive.notstringName of positive Z axis command matches not value
vrHandLocomotion.command.z.negativestringName of negative Z axis command matches value
vrHandLocomotion.command.z.negative.notstringName of negative Z axis command matches not value

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='vrHandLocomotion(right).running'>true</parameter>
  <parameter name='vrHandLocomotion(right).input.z.value.greater'>0.5</parameter>
  <condition>vrHandLocomotion(right).check</condition>
</action>

State Machine Actions

Same as Behavior Tree Actions.

State Machine Conditions

Same as 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

Optional Behaviors

Persistency

This behavior does not require element class to be persistable (setPersistable).

API Documentation

ECBehaviorVRHandLocomotion.

Since DragonScript Module Version 1.28

Use Cases

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 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:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorPlayerControllablenew'/>
  <behavior type='ECBehaviorVRPlayspace'/>
  <behavior type='ECBehaviorVRHand' id='right'/>
  <behavior type='ECBehaviorVRHand' id='left'/>
 
  <behavior type='ECBehaviorVRHandLocomotion' id='right'>
    <!-- required: use vr hand with id. -->
    <string name='vrHand'>right</string>
 
    <!-- optional: use BaseGameApp command manager. game can add more supported values.
                   default is 'default' -->
    <string name='commandManager'>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 -->
    <string name='.name'>value</string>
  </behavior>
 
  <behavior type='ECBehaviorVRHandLocomotion' id='left'>
    ...
  </behavior>
</elementClass>

Live Examples