{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorVRHandAction** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorVRHandAction ====== Behavior adding Action support to VR hands. Allows instance of #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BaseVRHandAction.html,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 #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorActorAIAction.html,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 #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BaseVRHandAction.html,BaseVRHandAction~@# is used. ====== Required Behaviors ====== * [[behavior_vrhand|ECBehaviorVRHand]] ====== Optional Behaviors ====== * [[behavior_conversationactor|ECBehaviorConversationAcotr]] ====== Persistency ====== Saves these parameters: * Active Action ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorVRHandAction.html,ECBehaviorVRHandAction~@#. Since DragonScript Module Version **1.10** ====== Use Cases ====== * Create player actions being processed for each hand in parallel ====== Element Class Example ====== The #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BaseVRActorClass.html,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 ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]: ExampleVR project.