User Tools

Site Tools


dragengine:modules:dragonscript:behavior_vrhandpointat

ECBehaviorVRHandPointAt

Behavior adding support to VR Hand behavior to know what element they are pointing at.

Behavior uses one collider collision test located attached controller collider facing forward.

If hand component is present and a test bone is set the collision test will be attached to the component bone.

By default the test direction is rotated by -45 degrees along the X axis. This accounts for VR hand controllers typically having their Z axis along the grip direction. This causes the point at detection to point 45 degrees upwards. For easier usage rotating the point at detection direction downwards by 45 degrees helps.

By default point-at is disabled for backwards compatibility.

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 vrHandPointAt. or vrHandPointAt(id). if id is not empty.

range

Range in meters to test for objects supporting to be pointed at.

  • Full name: vrHandPointAt.range or vrHandPointAt(id).range
  • Type: float
  • Restrictions: At least 0
  • Default Value: 2
  • Example (*.deeclass):
    <float name='vrHandPointAt(right).range'>3.5</float>

origin

Test origin relative to hand controller coordinate system.

  • Full name: vrHandPointAt.origin or vrHandPointAt(id).origin
  • Type: 3-component vector
  • Default value: (0, 0, 0)
  • Example (*.deeclass):
    <vector name='vrHandPointAt(left).origin' x='0' y='0.1' z='0.2'/>

rotation

Test rotation in degrees relative to hand controller coordinate system.

  • Full name: vrHandPointAt.rotation or vrHandPointAt(id).rotation
  • Type: 3-component vector
  • Default value: (0, 0, 0)
  • Example (*.deeclass):
    <vector name='vrHandPointAt(left).rotation' x='45' y='0' z='0'/>

bone

Name of bone in controller model to attach to or empty string to attach to the controller itself.

  • Full name: vrHandPointAt.bone or vrHandPointAt(id).bone
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass):
    <string name='vrHandPointAt(right).bone'>indexFinger</string>

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorVRHand.

Since DragonScript Module Version 1.7

Use Cases

  • Test what objects in the world the player is pointing at

Element Class Example

The following example creates an element class with support to test what element the player is pointing at:

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 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)
  end
end

The BaseVRActorClass provides full VR support including ECBehaviorVRHandPointAt 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'>
    <!-- required: use vr hand with id. -->
    <string name='vrHand'>right</string>
 
    <!-- optional: set collision filter. default value '1:0 1 2' which means
                   category BaseGameApp.CollisionFilterBit.dynamic
                   filter BaseGameApp.CollisionFilterBit.geometry,
                          BaseGameApp.CollisionFilterBit.dynamic,
                          BaseGameApp.CollisionFilterBit.actor.
                   format is '', 'category' or 'category:filter' where category and filter
                   are a list of bits to set. -->
    <string name='collisionFilter'>6:0 1 2 3 5</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
 
  <behavior type='ECBehaviorVRHandPointAt' id='left'>
    ...
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_vrhandpointat.txt · Last modified: 2025/03/12 22:39 by dragonlord