User Tools

Site Tools


dragengine:modules:dragonscript:behavior_grabspot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dragengine:modules:dragonscript:behavior_grabspot [2022/02/05 19:02] – created dragonlorddragengine:modules:dragonscript:behavior_grabspot [2025/05/13 14:06] (current) dragonlord
Line 1: Line 1:
 {{tag>dragonscript behavior}} {{tag>dragonscript behavior}}
 <WRAP youarehere> <WRAP youarehere>
-[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorGrabSpot**+[[: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]] >> **ECBehaviorGrabSpot**
 </WRAP> </WRAP>
  
Line 21: Line 21:
 ====== Element Class Properties ====== ====== Element Class Properties ======
  
-Element class properties have the prefix **grabSpot.** or **grabSpot(id)**. if id is not empty.+Element class properties have the prefix ''grabSpot.'' or ''grabSpot(id)''. if id is not empty.
  
 ===== touchCollider.physicsType ===== ===== touchCollider.physicsType =====
 Physics type of touch collider used to detect touching grabbers. Physics type of touch collider used to detect touching grabbers.
-  * Full name: "grabSpot.touchCollider.physicsTypeor "grabSpot(id).touchCollider.physicsType" +  * Full name: ''grabSpot.touchCollider.physicsType'' or ''grabSpot(id).touchCollider.physicsType'' 
-  * Type: string of values "none", "kinematic" and "dynamic" +  * Type: enumeration 
-  * Default Value: "kinematic"+  * <WRAP>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.| 
 +</WRAP> 
 +  * Default Value: ''kinematic''
   * Example (*.deeclass): <code xml><string name='grabSpotright).touchCollider.physicsType>kinematic</string></code>   * Example (*.deeclass): <code xml><string name='grabSpotright).touchCollider.physicsType>kinematic</string></code>
  
 ===== touchCollider.localGravity ===== ===== touchCollider.localGravity =====
 Local gravity of touch collider if not affected by world gravity. Local gravity of touch collider if not affected by world gravity.
-  * Full name: "grabber.touchCollider.localGravityor "grabber(id).touchCollider.localGravity"+  * Full name: ''grabber.touchCollider.localGravity'' or ''grabber(id).touchCollider.localGravity''
   * Type: 3-component vector   * Type: 3-component vector
-  * Default Value: (0, 0, 0)+  * Default Value: ''(0, 0, 0)''
   * Example (*.deeclass): <code xml><vector name='grabSpot(right).touchCollider.localGravity' x='0' y='-0.1' z='0'/></code>   * Example (*.deeclass): <code xml><vector name='grabSpot(right).touchCollider.localGravity' x='0' y='-0.1' z='0'/></code>
  
 ===== touchCollider.weight ===== ===== touchCollider.weight =====
 Weight (mass) of touch collider if dynamic. Weight (mass) of touch collider if dynamic.
-  * Full name: "grabber.touchCollider.weightor "grabber(id).touchCollider.weight"+  * Full name: ''grabber.touchCollider.weight'' or ''grabber(id).touchCollider.weight''
   * Type: float   * Type: float
-  * Default Value: 1+  * Default Value: ''1''
   * Example (*.deeclass): <code xml><float name='grabSpot(right).touchCollider.weight'>0.2</float></code>   * Example (*.deeclass): <code xml><float name='grabSpot(right).touchCollider.weight'>0.2</float></code>
  
 ===== touchCollider.enabled ===== ===== touchCollider.enabled =====
 Initial enabled state of touch collider. Initial enabled state of touch collider.
-  * Full name: "grabber.touchCollider.enabledor "grabber(id).touchCollider.enabled"+  * Full name: ''grabber.touchCollider.enabled'' or ''grabber(id).touchCollider.enabled''
   * Type: boolean   * Type: boolean
-  * Default Value: true+  * Default Value: ''true''
   * Example (*.deeclass): <code xml><boolean name='grabSpot(right).touchCollider.enabled'>true</float></code>   * Example (*.deeclass): <code xml><boolean name='grabSpot(right).touchCollider.enabled'>true</float></code>
  
 ===== touchCollider.shape ===== ===== touchCollider.shape =====
 Shape of touch collider used to detect grabbers. Shape of touch collider used to detect grabbers.
-  * Full name: "grabSpot.touchCollider.shapeor "grabSpot(id).touchCollider.shape" +  * Full name: ''grabSpot.touchCollider.shape'' or ''grabSpot(id).touchCollider.shape'' 
-  * Type: string (shape list encoding)+  * Type: string (shape format). See "Shape List Encoding" in CodecPropertyString.
   * Default Value: empty string   * Default Value: empty string
   * Example (*.deeclass): <code xml><string name='grabber(right).touchCollider.shape'>box:extends,0.1,0.1,0.1</string></code>   * Example (*.deeclass): <code xml><string name='grabber(right).touchCollider.shape'>box:extends,0.1,0.1,0.1</string></code>
Line 60: Line 66:
 ===== touchCollider.rig ===== ===== touchCollider.rig =====
 Rig resource to use for touch collider. Rig resource to use for touch collider.
-  * Full name: "grabSpot.touchCollider.rigor "grabSpot(id).touchCollider.rig" +  * Full name: ''grabSpot.touchCollider.rig'' or ''grabSpot(id).touchCollider.rig'' 
-  * Type: string (rig resource path, for example *.derig)+  * Type: string 
 +  * File Pattern: ''*.derig'' (all rig modules)
   * Default Value: empty path   * Default Value: empty path
   * Example (*.deeclass): <code xml><string name='grabSpot(right).touchCollider.rig'>grab_spot.derig</string></code>   * Example (*.deeclass): <code xml><string name='grabSpot(right).touchCollider.rig'>grab_spot.derig</string></code>
  
-===== attach.position =====+===== position =====
 Touch collider attach position relative to parent element or bone. Touch collider attach position relative to parent element or bone.
-  * Full name: "grabSpot.attach.positionor "grabSpot(id).attach.position"+  * Full name: ''grabSpot.position'' or ''grabSpot(id).position''
   * Type: 3-component vector   * Type: 3-component vector
-  * Default Value: (0, 0, 0) +  * Default Value: ''(0, 0, 0)'' 
-  * Example (*.deeclass): <code xml><vector name='grabSpot(right).attach.position' x='0' y='0' z='0.1'/></code>+  * Example (*.deeclass): <code xml><vector name='grabSpot(right).position' x='0' y='0' z='0.1'/></code>
  
-===== attach.rotation =====+===== rotation =====
 Touch collider attach orientation in euler degrees relative to parent element or bone. Touch collider attach orientation in euler degrees relative to parent element or bone.
-  * Full name: "grabSpot.attach.rotationor "grabSpot(id).attach.rotation"+  * Full name: ''grabSpot.rotation'' or ''grabSpot(id).rotation''
   * Type: 3-component vector   * Type: 3-component vector
-  * Default Value: (0, 0, 0) +  * Default Value: ''(0, 0, 0)'' 
-  * Example (*.deeclass): <code xml><vector name='grabSpot(right).attach.rotation' x='-45' y='0' z='0'/></code>+  * Example (*.deeclass): <code xml><vector name='grabSpot(right).rotation' x='-45' y='0' z='0'/></code>
  
-===== attach.bone =====+===== bone =====
 Name of bone to attach touch collider to or empty string to attach to the parent element. Name of bone to attach touch collider to or empty string to attach to the parent element.
-  * Full name: "grabSpot.attach.boneor "grabSpot(id).attach.bone"+  * Full name: ''grabSpot.bone'' or ''grabSpot(id).bone''
   * Type: string   * Type: string
   * Default Value: empty string   * Default Value: empty string
-  * Example (*.deeclass): <code xml><string name='grabSpot(right).attach.bone'>attach hand.r</string></code>+  * Example (*.deeclass): <code xml><string name='grabSpot(right).bone'>attach hand.r</string></code> 
 + 
 +====== Events ====== 
 + 
 +===== spotGrabbed ===== 
 + 
 +Grabber has grabbed spot. 
 + 
 +===== spotReleased ===== 
 + 
 +Grabber has release spot. 
 + 
 +===== enabledChanged ===== 
 + 
 +Grab spot enabled changed. 
 + 
 +====== Behavior Tree Actions ====== 
 + 
 +This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''grabSpot'' with ''grabSpot(id)''
 + 
 +===== grabSpot.set ===== 
 + 
 +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: 
 +<code xml> 
 +<action name='grabSpot.set'> 
 +  <parameter name='enabled'>true</parameter> 
 +</action> 
 +</code> 
 + 
 +===== grabSpot.update ===== 
 + 
 +Update grab spot. 
 + 
 +^Parameter^Value^Description^ 
 +|release| |Release grabber if one is grabbing the grab spot.| 
 +|interactElement.assign|string|Assign grabber element to [[behavior_interactelement|ECBehaviorInteractElement]] with identifier matching value string. Action fails if no element is grabbing or interact element behavior is absent| 
 +|interact|string|Interact with grabber. If element is absent action fails. Runs interaction with name value. If interaction with name value is absent fails action. If interaction returns false fails action. Otherwise action succeeds.| 
 +|interact.parameters|string|Optional parameters to use with ''interaction''.| 
 + 
 +This is an example of using this action: 
 +<code xml> 
 +<action name='grabSpot.update'> 
 +  <parameter name='release'/> 
 +</action> 
 +</code> 
 + 
 +===== grabSpot.check ===== 
 + 
 +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| 
 +|interact.name|string|Name of interaction| 
 +|interact.has|''true'', ''false''|Has grabber and interaction with name ''interaction.name'' is present| 
 +|interact.query|''true'', ''false''|Interact with grabber and test result. Condition is true if grabber is present, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).| 
 +|interact.parameters|string|Optional parameters to use with ''interaction.query''.| 
 +|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: 
 +<code xml> 
 +<sequence> 
 +  <action name='grabSpot.check'> 
 +    <parameter name='grabbed'>true</parameter> 
 +  </action> 
 +  <!-- actions here run only if grab spot is grabbed by a grabber --> 
 +</sequence> 
 +</code> 
 + 
 +====== Behavior Tree Conditions ====== 
 + 
 +This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''grabSpot'' with ''grabSpot(id)''
 + 
 +===== grabSpot.check ===== 
 + 
 +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| 
 +|grabSpot.interact.name|string|Name of interaction| 
 +|grabSpot.interact.has|''true'', ''false''|Has grabber and interaction with name ''interaction.name'' is present| 
 +|grabSpot.interact.query|''true'', ''false''|Interact with grabber and test result. Condition is true if grabber is present, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).| 
 +|grabSpot.interact.parameters|string|Optional parameters to use with ''interaction.query''.| 
 + 
 +This is an example of using this condition: 
 +<code xml> 
 +<action name='myAction' id='doing something'> 
 +  <parameter name='grabSpot.grabbed'>true</parameter> 
 +  <condition>grabSpot.check</condition> 
 +</action> 
 +</code> 
 + 
 +====== 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 these state machine events. If behavior has non-empty identifier replace ''grabSpot'' with ''grabSpot(id)''
 + 
 +===== grabSpot.enabled ===== 
 + 
 +Grab spot has been enabled. 
 + 
 +===== grabSpot.disabled ===== 
 + 
 +Grab spot has been disabled. 
 + 
 +===== grabSpot.grabbed ===== 
 + 
 +Grabber grabbed grab spot. 
 + 
 +===== grabSpot.released ===== 
 + 
 +Grabber released grab spot.
  
 ====== Required Behaviors ====== ====== Required Behaviors ======
-This behavior does not required other behaviors to be present. + 
 +This behavior does not required other behaviors to be present.
  
 ====== Optional Behaviors ====== ====== Optional Behaviors ======
  
   * [[behavior_collider|ECBehaviorCollider]]: If used attaches grab spot touch collider to collider   * [[behavior_collider|ECBehaviorCollider]]: If used attaches grab spot touch collider to collider
 +  * [[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 ====== ====== Persistency ======
  
-Saves these parameters: +This behavior does support element class to be persistable (setPersistable).
- +
-  * Enabled +
-  * [[behavior_grabber|ECBehaviorGrabber]]+
  
 ====== API Documentation ====== ====== API Documentation ======
-[[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorGrabSpot.html|ECBehaviorGrabSpot]].+#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorGrabSpot.html,ECBehaviorGrabSpot~@#.
  
-Since DragonScript Module Version **1.9**+Since DragonScript Module Version ''1.9''
  
 ====== Use Cases ====== ====== Use Cases ======
 +
   * Allow player to grab objects in VR with his hands.   * Allow player to grab objects in VR with his hands.
   * Add different grab spots on an object in VR to alter the interactions the player can do.   * Add different grab spots on an object in VR to alter the interactions the player can do.
Line 127: Line 260:
    end    end
 end end
 +</code>
 +
 +====== Behavior Factory ======
 +
 +Using element class supporting adding behaviors the behavior can be added like this:
 +<code xml>
 +<?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>
 </code> </code>
  
dragengine/modules/dragonscript/behavior_grabspot.1644087751.txt.gz · Last modified: 2022/02/05 19:02 by dragonlord