User Tools

Site Tools


dragengine:modules:dragonscript:behavior_vrhandlaserpointer

ECBehaviorVRHandLaserPointer

Behavior element behavior adding VR Hand Controller Laser Pointer support to actor.

VR Hand Controllers often use a laser pointer type interaction.

This behavior adds a particle emitter representing the laser pointer. The behavior attaches itself to a ECBehaviorVRHandPointAt. The enable casting of the particle emitter is linked to the enabled state of ECBehaviorVRHandPointAt.

Named controllers can be used to set typically laserpointer parameters at runtime if the named controllers exist. The following named controllers are supported:

  • length: Length of unobstructed beam in meters.
  • intensity: Intensity of beam.
  • red: Red color component of beam.
  • green: Green color component of beam.
  • blue: Blue color component of beam.

Additional named controllers can be added if required. The default particle emitter used is /shareddata/particles/laserpointer/laserpointer.depemit. This particle emitter defines the controller ranges like this:

  • length: Between 0m to 10m.
  • intensity: Between 0 to 1. The beam skin uses camera adapted intensity hence 1 represents full bright intensits compared to camera upper intensity.
  • red, green, blue: All betwen 0 to 1.

The default particle emitter is set to use custom collision response. This behavior implements the response to make the beam stop at the first hit obstacle. The collision filter from ECBehaviorVRHandPointAt is copied to the particle emitter to ensure the results are comparable.

The particle emitter is aligned with the test direction.

Instance Counts

This behavior can be added twice to an element to add support for left and right hand controller. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix vrHandLaserPointer. or vrHandLaserPointer(id). if id is not empty.

particleEmitter.*

This behavior adds a child ECBehaviorParticleEmitter to the element class to show the laser pointer in the game world. The child behavior has the identifier vrHandLaserPointer or vrHandLaserPointer(id). The child behavior has the element class property prefix vrHandLaserPointer.particleEmitter. or vrHandLaserPointer(id).particleEmitter. .

Hence to set for example the particle emitter of the right hand use the element class property vrHandLaserPointer(right).particleEmitter.path .

controllerLength

Name of particle emitter controller to update with laserpointer length or empty string if not used.

  • Full name: vrHandLaserPointer.controllerLength or vrHandLaserPointer(id).controllerLength
  • Type: string
  • Default Value: length
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerLength'>length</string>

controllerIntensity

Name of particle emitter controller to update with laserpointer intensity or empty string if not used.

  • Full name: vrHandLaserPointer.controllerIntensity or vrHandLaserPointer(id).controllerIntensity
  • Type: string
  • Default Value: intensity
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerIntensity'>intensity</string>

controllerRed

Name of particle emitter controller to update with laserpointer red color component or empty string if not used.

  • Full name: vrHandLaserPointer.controllerRed or vrHandLaserPointer(id).controllerRed
  • Type: string
  • Default Value: red
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerRed'>red</string>

controllerGreen

Name of particle emitter controller to update with laserpointer green color component or empty string if not used.

  • Full name: vrHandLaserPointer.controllerGreen or vrHandLaserPointer(id).controllerGreen
  • Type: string
  • Default Value: green
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerGreen'>green</string>

controllerBlue

Name of particle emitter controller to update with laserpointer blue color component or empty string if not used.

  • Full name: vrHandLaserPointer.controllerBlue or vrHandLaserPointer(id).controllerBlue
  • Type: string
  • Default Value: blue
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerBlue'>blue</string>

length

Length in meters of laser pointer.

  • Full name: vrHandLaserPointer.length or vrHandLaserPointer(id).length
  • Type: float
  • Restrictions: At least 0
  • Default Value: 10
  • Example (*.deeclass):
    <float name='vrHandLaserPointer(right).length'>15</float>

intensity

Intensity of laser pointer. The actual intensity used depends on the particle emitter. Usually particle emitters use camera adapted intensity which maps an intensity of 1 to the camera upper intensity.

  • Full name: vrHandLaserPointer.intensity or vrHandLaserPointer(id).intensity
  • Type: float
  • Restrictions: At least 0
  • Default Value: 0.4
  • Example (*.deeclass):
    <float name='vrHandLaserPointer(right).intensity'>0.8</float>

color

Color of laser pointer.

  • Full name: vrHandLaserPointer.color or vrHandLaserPointer(id).color
  • Type: 3-component color
  • Default Value: (0, 1, 1)
  • Example (*.deeclass):
    <color name='vrHandLaserPointer(right).color' r='1' g='1' b='0'/>

Events

This behavior has no events.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace vrHandLaserPointer with vrHandLaserPointer(id).

vrHandLaserPointer.set

Set one or more VR hand laser pointer parameters.

ParameterValueDescription
lengthfloatLength of beam in meters
intensityfloatIntensity of beam
colorcolorColor of beam

This is an example of using this action:

<action name='vrHandLaserPointer.set'>
  <parameter name='color'>1 0 0</parameter>
</action>

vrHandLaserPointer.check

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

ParameterValueDescription
length.lessfloatLength of beam is less than value meters
length.greaterfloatLength of beam is greater than value meters
intensity.lessfloatIntensity of beam is less than value meters
intensity.greaterfloatIntensity of beam is greater than value meters
color.red.lessfloatRed color of beam is less than value
color.red.greaterfloatRed color of beam is greater than value
color.green.lessfloatGreen color of beam is less than value
color.green.greaterfloatGreen color of beam is greater than value
color.blue.lessfloatBlue color of beam is less than value
color.blue.greaterfloatBlue color of beam is greater than 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='vrHandLaserPointer.check'>
    <parameter name='intensity.less'>0.5</parameter>
  </action>
  <!-- actions here run only if intensity of beam is less than 50% -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace vrHandLaserPointer with vrHandLaserPointer(id).

vrHandLaserPointer.check

Check one or more VR hand laser pointer parameters. Conditions returns true if all parameter value match their respective VR hand laser pointer parameter. This condition is typically used to run an action or sequence of actions as long as VR hand laser pointer conditions are true.

ParameterValueDescription
vrHandLaserPointer.length.lessfloatLength of beam is less than value meters
vrHandLaserPointer.length.greaterfloatLength of beam is greater than value meters
vrHandLaserPointer.intensity.lessfloatIntensity of beam is less than value meters
vrHandLaserPointer.intensity.greaterfloatIntensity of beam is greater than value meters
vrHandLaserPointer.color.red.lessfloatRed color of beam is less than value
vrHandLaserPointer.color.red.greaterfloatRed color of beam is greater than value
vrHandLaserPointer.color.green.lessfloatGreen color of beam is less than value
vrHandLaserPointer.color.green.greaterfloatGreen color of beam is greater than value
vrHandLaserPointer.color.blue.lessfloatBlue color of beam is less than value
vrHandLaserPointer.color.blue.greaterfloatBlue color of beam is greater than value

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='vrHandLaserPointer.intensity.less'>0.5</parameter>
  <condition>vrHandLaserPointer.check</condition>
</action>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends no state machine events.

Required Behaviors

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorVRHandLaserPointer.

Since DragonScript Module Version 1.7

Use Cases

  • Show a laser pointer in VR to visualize what objects the player interacts with.

Element Class Example

The following example creates an element class with laser pointer support.

class MyElement extends BehaviorElementClass
   public var ECBehaviorVRPlayspace vrPlayspace
   public var ECBehaviorVRHand vrHandRight
   public var ECBehaviorVRHand vrHandLeft
   public var ECBehaviorVRHandPointAt vrRightHandPointAt
   public var ECBehaviorVRHandPointAt vrLeftHandPointAt
   public var ECBehaviorVRHandLaserPointer vrRightHandLaserPointer
   public var ECBehaviorVRHandLaserPointer vrLeftHandLaserPointer
   
   public func new()
      // 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 point at behavior for each hand. By default the test direction
      // is along the controller Z axis. For common controllers this points
      // along the handle direction which is like holding a sword or similar
      vrRightHandPointAt = ECBehaviorVRHandPointAt.new(this, vrRightHand, "right")
      vrLeftHandPointAt = ECBehaviorVRHandPointAt.new(this, vrLeftHand, "left")
      
      // If you have a ECBehaviorCollider in your element class it is a good idea
      // to ignore this collider. This avoids the point hitting the player body
      // or hands.
      
      // vrRightHandPointAt.setIgnoreCollider(collider)
      // vrLeftHandPointAt.setIgnoreCollider(collider)
      
      // Add laser pointers. These are disabled by default. Enable them in
      // actor actions for example when the player touches the track pad
      // on his controller or whenever a specific actor action activates
      vrRightHandLaserPointer = ECBehaviorVRHandLaserPointer.new(this, vrRightHandPointAt, "right")
      vrLeftHandLaserPointer = ECBehaviorVRHandLaserPointer.new(this, vrLeftHandPointAt, "left")
  end
end

The BaseVRActorClass provides full VR support including ECBehaviorVRHandLaserPointer 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='ECBehaviorVRPlayspace'/>
  <behavior type='ECBehaviorVRHand' id='right'/>
  <behavior type='ECBehaviorVRHand' id='left'/>
  <behavior type='ECBehaviorVRHandPointAt' id='right'>
    <string name='vrHand'>right</string>
  </behavior>
  <behavior type='ECBehaviorVRHandPointAt' id='left'>
    <string name='vrHand'>left</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>
  </behavior>
 
  <behavior type='ECBehaviorVRHandLaserPointer' id='right'>
    <!-- required: use vr hand point at with id -->
    <string name='vrHandPointAt'>right</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
 
  <behavior type='ECBehaviorVRHandLaserPointer' id='left'>
    <string name='vrHandPointAt'>left</string>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_vrhandlaserpointer.txt · Last modified: 2025/05/14 10:44 by dragonlord