Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorGrabSpot
Behavior adding support to define grab spot for actors.
Defines position and orientation where the actor can grab the owner element. 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 an actor is grabbing the grab spot. Hence at most one actor can grab an grab spot at each time.
Elements able to grab a grab spot have to use the ECBehaviorGrabber behavior. Both the grab spot and the grabber have to persist the other behavior. During restoring no notifications are triggered this way.
This behavior can be used multiple times on an element to add different grab spots. Use the behavior identifier to tell them apart.
Element class properties have the prefix grabSpot.
or grabSpot(id)
. if id is not empty.
Physics type of touch collider used to detect touching grabbers.
grabSpot.touchCollider.physicsType
or grabSpot(id).touchCollider.physicsType
Allowed Values:
Value | Description |
---|---|
none | Collider is not moving and will not move by collisions. |
dynamic | Collider reacts to impacts using physical simulation. |
kinematic | Game scripts define the collision response. |
kinematic
<string name='grabSpotright).touchCollider.physicsType>kinematic</string>
Local gravity of touch collider if not affected by world gravity.
grabber.touchCollider.localGravity
or grabber(id).touchCollider.localGravity
(0, 0, 0)
<vector name='grabSpot(right).touchCollider.localGravity' x='0' y='-0.1' z='0'/>
Weight (mass) of touch collider if dynamic.
grabber.touchCollider.weight
or grabber(id).touchCollider.weight
1
<float name='grabSpot(right).touchCollider.weight'>0.2</float>
Initial enabled state of touch collider.
grabber.touchCollider.enabled
or grabber(id).touchCollider.enabled
true
<boolean name='grabSpot(right).touchCollider.enabled'>true</float>
Shape of touch collider used to detect grabbers.
grabSpot.touchCollider.shape
or grabSpot(id).touchCollider.shape
<string name='grabber(right).touchCollider.shape'>box:extends,0.1,0.1,0.1</string>
Rig resource to use for touch collider.
grabSpot.touchCollider.rig
or grabSpot(id).touchCollider.rig
*.derig
(all rig modules)<string name='grabSpot(right).touchCollider.rig'>grab_spot.derig</string>
Touch collider attach position relative to parent element or bone.
grabSpot.position
or grabSpot(id).position
(0, 0, 0)
<vector name='grabSpot(right).position' x='0' y='0' z='0.1'/>
Touch collider attach orientation in euler degrees relative to parent element or bone.
grabSpot.rotation
or grabSpot(id).rotation
(0, 0, 0)
<vector name='grabSpot(right).rotation' x='-45' y='0' z='0'/>
Name of bone to attach touch collider to or empty string to attach to the parent element.
grabSpot.bone
or grabSpot(id).bone
<string name='grabSpot(right).bone'>attach hand.r</string>
Grabber has grabbed spot.
Grabber has release spot.
Grab spot enabled changed.
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace grabSpot
with grabSpot(id)
.
Set one or more grab spot parameters.
Parameter | Value | Description |
---|---|---|
enabled | true , false | Grab spot is enabled |
This is an example of using this action:
<action name='grabSpot.set'> <parameter name='enabled'>true</parameter> </action>
Release grabber if one is grabbing the grab spot.
This is an example of using this action:
<action name='grabSpot.release'/>
Check one or more grab spot parameters. Action succeeds if all parameter value matches their respective grab spot parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a grab spot parameter matches (or not).
Parameter | Value | Description |
---|---|---|
enabled | true , false | Grab spot is enabled |
grabbed | true , false | Grab spot is grabbed by a grabber |
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='grabSpot.check'> <parameter name='grabbed'>true</parameter> </action> <!-- actions here run only if grab spot is grabbed by a grabber --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace grabSpot
with grabSpot(id)
.
Check one or more grab spot parameters. Conditions returns true if all parameter value match their respective grab spot parameter. This condition is typically used to run an action or sequence of actions as long as grab spot conditions are true.
Parameter | Value | Description |
---|---|---|
grabSpot.enabled | true , false | Grab spot is enabled |
grabSpot.grabbed | true , false | Grab spot is grabbed by a grabber |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='grabSpot.grabbed'>true</parameter> <condition>grabSpot.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 grabSpot
with grabSpot(id)
.
Grab spot has been enabled.
Grab spot has been disabled.
Grabber grabbed grab spot.
Grabber released grab spot.
This behavior does not required other behaviors to be present.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.9
class ExampleElementClass extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorGrabSpot grabSpot public func new() super("ExampleElement") // Create component and collider to give element a look and feeling component = ECBehaviorComponent.new(this) collider = ECBehaviorCollider.new(this, component) // Create grab spot 10cm along Z axis grabSpot = ECBehaviorGrabSpot.new(this, collider) grabSpot.getAttachTouchCollider().getPosition().setVector(Vector.new(0, 0, 0.1)) end end
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='ECBehaviorComponent'/> <behavior type='ECBehaviorCollider'/> <behavior type='ECBehaviorGrabSpot'> <!-- 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='.name'>Color 1</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorGrabSpot' id='second'/> </elementClass>