Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorGrabber
Behavior adding support to grab an ECBehaviorGrabSpot.
Grab spots are typically used for physics interaction like VR hand use but can be used also with mouse interaction. The actual grabbing interaction, exact grab location and orientation as well as attaching logic is handled by other behaviors using listening. This behavior also tracks if what grab spot an actor is grabbing. Hence at most one grab spot can be grabbed by this behavior at each time.
Elements able to be grabbed have to use the ECBehaviorGrabSpot behavior. Both the grab spot and the grabber have to persist the other behavior. During restoring no notifications are triggered this way.
To detect grab spots a touch sensor is added with a default sphere shape. By default the touch sensor is disabled and has to be enabled if the game logic allows grabbing. The collision filter category is set to BaseGameApp.CollisionFilterBit.trigger and the collision filter mask is set to BaseGameApp.CollisionFilterBit.dynamic.
This behavior can be added multiple times to an element. Use the behavior identifier to tell them apart.
Element class properties have the prefix grabber.
or grabber(id).
if id is not empty.
Shape of collider used to detect grab spots.
grabber.shape
or grabber(id).shape
<string name='grabber(right).shape'>box:extends,0.1,0.1,0.1</string>
Attach position relative to parent element or bone.
grabber.position
or grabber(id).position
(0, 0, 0)
<vector name='grabber(right).position' x='0' y='0' z='0.1'/>
Attach orientation in euler degrees relative to parent element or bone.
grabber.rotation
or grabber(id).rotation
(0, 0, 0)
<vector name='grabber(right).rotation' x='-45' y='0' z='0'/>
Name of bone to attach to or empty string to attach to the parent element.
grabber.bone
or grabber(id).bone
<string name='grabber(right).bone'>attach hand.r</string>
Grabber grabbed grab spot.
Grabber released grab spot.
Start touching grab spot.
Stop touching grab spot.
Grab spot can be touched if all listeners return true.
Grabber enabled changed.
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace grabber
with grabber(id)
.
Set one or more grabber parameters.
Parameter | Value | Description |
---|---|---|
enabled | true , false | Grabber is enabled |
This is an example of using this action:
<action name='grabber.set'> <parameter name='enabled'>true</parameter> </action>
Release grab spot if grabbing one.
This is an example of using this action:
<action name='grabber.release'/>
Check one or more grabber parameters. Action succeeds if all parameter value matches their respective grabber parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a grabber parameter matches (or not).
Parameter | Value | Description |
---|---|---|
enabled | true , false | Grabber is enabled |
grabbing | true , false | Grabber is grabbing a grab spot |
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='grabber.check'> <parameter name='grabbing'>true</parameter> </action> <!-- actions here run only if grabber is grabbing a grab spot --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace grabber
with grabber(id)
.
Check one or more grabber parameters. Conditions returns true if all parameter value match their respective grabber parameter. This condition is typically used to run an action or sequence of actions as long as grabber conditions are true.
Parameter | Value | Description |
---|---|---|
grabber.enabled | true , false | Grabber is enabled |
grabber.grabbing | true , false | Grabber is grabbing a grab spot |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='grabber.grabbing'>true</parameter> <condition>grabber.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends these state machine events. If behavior has non-empty identifier replace grabber
with grabber(id)
.
Grabber has been enabled.
Grabber has been disabled.
Grabber grabbed grab spot.
Grabber released grab spot.
Start touching grab spot.
Stop touching grab spot.
This behavior does require other behaviors.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.9
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 ECBehaviorGrabber vrRightHandGrabber public var ECBehaviorGrabber vrLeftHandGrabber 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 grabbers for each hand vrRightHandGrabber = ECBehaviorGrabber.new(this, vrRightHand, "right") vrLeftHandGrabber = ECBehaviorGrabber.new(this, vrLeftHand, "left") end end
The BaseVRActorClass provides full VR support including ECBehaviorGrabber for both hands.
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='ECBehaviorGrabber' id='right'> <!-- optional: use vr hand with id instead of empty string --> <string name='vrHand'>right</string> <!-- optional: set collision filter. default value '4:1' which means category BaseGameApp.CollisionFilterBit.trigger filter BaseGameApp.CollisionFilterBit.dynamic. format is '', 'category' or 'category:filter' where category and filter are a list of bits to set. --> <string name='collisionFilter'>4:1 2</string> <!-- optional: use behavior tree with id instead of empty string --> <string name='behaviorTree'>second</string> <!-- optional: use state machine with id instead of empty string --> <string name='stateMachine'>second</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.bone'>hand.r</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorCustomColor' id='left'> <string name='vrHand'>left</string> <string name='.bone'>hand.l</string> </behavior> </elementClass>