User Tools

Site Tools


dragengine:modules:dragonscript:behavior_vrhandaction

ECBehaviorVRHandAction

Behavior adding Action support to VR hands.

Allows instance of BaseVRHandAction to be assigned to actor VR hands. During thinking the Action is called.

Actions allow actors to perform a specific, well defined and enclosed action like interacting with an object for each hand separately. These actions run after the main actor action as provided by ECBehaviorActorAIAction. VR hand actions are typically nly suitable for the player.

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

Thie behavior adds no element class properties.

Using this behavior in code you should call ECBehaviorVRHandAction.setActionFactory() to set the factory creating the initial action for the hand to use. By default an instance of BaseVRHandAction is used.

Required Behaviors

Optional Behaviors

Persistency

Saves these parameters:

  • Active Action

API Documentation

ECBehaviorVRHandAction.

Since DragonScript Module Version 1.10

Use Cases

  • Create player actions being processed for each hand in parallel

Element Class Example

The BaseVRActorClass provides support for right and left hand actions. See BaseVRActorClass.getVRRightHandAction() and BaseVRActorClass.getVRLeftHandAction() to get access to the behaviors on class side and BaseVRActor.getVRRightHandAction() and BaseVRActor.getVRLeftHandAction() to access the behavior instance on actor instance side.

The following example creates an element class adding the action elements manually.

// Hand action class. Create one for each action your actor can support
class MyHandAction extends BaseVRHandAction
   // Factory for creating action
   class Factory implements ECBehaviorVRHandAction.ActionFactory
      public static fixed var String name = "MyHandAction"
      
      // Create factory
      public func new()
      end
      
      // Create action
      func BaseVRHandAction createAction(ECBehaviorVRHandAction.Instance instance)
         return MyHandAction.new()
      end
   end
   

   // Create action. The actor and vrhand behavior will be assigned during activate() call.
   public func new()
   end
   
   // Implement this method and super-call to obtain the behaviors from the
   // actor class you want to work with. This is optional and avoids the need
   // to fetch the behavior instances all the time if used. It also makes the
   // code easier to read and reduces error
   protected func void initBehaviors()
      super.initBehaviors()
      
      /*
      // Get behavior instance matching hand. For this to work you have to
      // use BaseVRActorClass.idVRRightHand or BaseVRActorClass.idVRLeftHand
      // as behavior identifier. Then you can use this line below.
      myBehavior = ECBehaviorMyBehavior.instance(actor, vrHand.getECBehavior().getID())
      
      // If you use other identifiers you have to use an if-else
      if vrHand.getECBehavior().getID().equals(BaseVRActorClass.idVRRightHand)
         myBehavior = ECBehaviorMyBehavior.getInstanceIn(actor, "rightHandId")
      else
         myBehavior = ECBehaviorMyBehavior.getInstanceIn(actor, "leftHandId")
      end
      */
   end
end


class MyElement extends BehaviorElementClass
   public var ECBehaviorConversationActor conversationActor
   public var ECBehaviorVRPlayspace vrPlayspace
   public var ECBehaviorVRHand vrHandRight
   public var ECBehaviorVRHand vrHandLeft
   public var ECBehaviorVRHandAction vrRightHandAction
   public var ECBehaviorVRHandAction vrLeftHandAction
   
   public func new()
      // Create conversation actor. For the full experience you need also the
      // commented out parts
      conversationActor = ECBehaviorConversationActor.new(this)
      // conversationActor.setActorAnimated(actorAnimated) // ECBehaviorActorAnimated
      // conversationActor.setLocomotion(locomotion) // ECBehaviorLocomotion
      
      // 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, BaseVRActorClass.idVRRightHand)
      vrHandLeft = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrLeftHand, BaseVRActorClass.idVRLeftHand)
      
      // Create action behavior for each hand
      vrRightHandAction = ECBehaviorVRHandAction.new(this, vrRightHand, conversationActor, BaseVRActorClass.idVRRightHand)
      vrLeftHandAction = ECBehaviorVRHandAction.new(this, vrLeftHand, conversationActor, BaseVRActorClass.idVRLeftHand)
      
      // Assign factories to create the initial hand actions.
      vrRightHandAction.setActionFactory(MyHandAction.Factory.new())
      vrLeftHandAction.setActionFactory(MyHandAction.Factory.new())
  end
end

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_vrhandaction.txt · Last modified: 2024/03/14 16:44 by dragonlord