{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorVRHandLaserPointer** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== 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 [[behavior_vrhandpointat|ECBehaviorVRHandPointAt]]. The enable casting of the particle emitter is linked to the enabled state of [[behavior_vrhandpointat|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 [[behavior_vrhandpointat|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 [[behavior_particleemitter|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): length ===== 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): intensity ===== 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): red ===== 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): green ===== 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): blue ===== 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): 15 ===== 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): 0.8 ===== color ===== Color of laser pointer. * Full name: ''vrHandLaserPointer.color'' or ''vrHandLaserPointer(id).color'' * Type: 3-component color * Default Value: ''(0, 1, 1)'' * Example (*.deeclass): ====== 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. ^Parameter^Value^Description^ |length|float|Length of beam in meters| |intensity|float|Intensity of beam| |color|color|Color of beam| This is an example of using this action: 1 0 0 ===== 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). ^Parameter^Value^Description^ |length.less|float|Length of beam is less than value meters| |length.greater|float|Length of beam is greater than value meters| |intensity.less|float|Intensity of beam is less than value meters| |intensity.greater|float|Intensity of beam is greater than value meters| |color.red.less|float|Red color of beam is less than value| |color.red.greater|float|Red color of beam is greater than value| |color.green.less|float|Green color of beam is less than value| |color.green.greater|float|Green color of beam is greater than value| |color.blue.less|float|Blue color of beam is less than value| |color.blue.greater|float|Blue 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: 0.5 ====== 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. ^Parameter^Value^Description^ |vrHandLaserPointer.length.less|float|Length of beam is less than value meters| |vrHandLaserPointer.length.greater|float|Length of beam is greater than value meters| |vrHandLaserPointer.intensity.less|float|Intensity of beam is less than value meters| |vrHandLaserPointer.intensity.greater|float|Intensity of beam is greater than value meters| |vrHandLaserPointer.color.red.less|float|Red color of beam is less than value| |vrHandLaserPointer.color.red.greater|float|Red color of beam is greater than value| |vrHandLaserPointer.color.green.less|float|Green color of beam is less than value| |vrHandLaserPointer.color.green.greater|float|Green color of beam is greater than value| |vrHandLaserPointer.color.blue.less|float|Blue color of beam is less than value| |vrHandLaserPointer.color.blue.greater|float|Blue color of beam is greater than value| This is an example of using this condition: 0.5 vrHandLaserPointer.check ====== State Machine Actions ====== Same as [[#behavior_tree_actions|Behavior Tree Actions]]. ====== State Machine Conditions ====== Same as [[#behavior_tree_conditions|Behavior Tree Conditions]]. ====== State Machine Events ====== This behavior sends no state machine events. ====== Required Behaviors ====== * [[behavior_vrhandpointat|ECBehaviorVRHandPointAt]] ====== Optional Behaviors ====== * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use. * [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine. ====== Persistency ====== This behavior does support element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorVRHandLaserPointer.html,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 #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BaseVRActorClass.html,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: right left default default right value left ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]: ExampleVR project.