User Tools

Site Tools


dragengine:modules:dragonscript:behavior_touchsensor

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dragengine:modules:dragonscript:behavior_touchsensor [2025/03/13 16:48] – dragonlorddragengine:modules:dragonscript:behavior_touchsensor [2026/11/20 16:51] (current) – [touchSensor.set] 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]] >> **ECBehaviorTouchSensor**+[[: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]] >> **ECBehaviorTouchSensor**
 </WRAP> </WRAP>
  
Line 30: Line 30:
  
 Element class properties have the prefix ''touchSensor.'' or ''touchSensor({id}).'' if id is not empty. Element class properties have the prefix ''touchSensor.'' or ''touchSensor({id}).'' if id is not empty.
 +
 +===== bone =====
 +
 +Bone to attach resource to. If empty string attach to collider.
 +
 +  * Full name: ''touchSensor.bone'' or ''touchSensor({id}).bone''
 +  * Type: string
 +  * Default Value: empty string
 +  * Example (*.deeclass) <code xml><string name='touchSensor.bone'>attach</string></code>
 +
 +===== collisionFilter =====
 +
 +Set [[gamedev:collisionfiltering|collision filter]]. Filter bits are defined using a list of names mapped to collision filter bit indices using BaseGameApp.getCollisionFilterMap(). 
 +  * Full name: ''collider.collisionFilter''
 +  * Type: string. Format can be ''category:filter'' or ''category'' where category and filter can be ''bit1 bit2 ... bitN'' with bit names looked up using the collision filter map. If only category is used filter is the same.
 +  * Default Value: ''trigger:actorAI''
 +  * Example (*.deeclass) <code xml><string name='collider.collisionFilter'>trigger:actorAI particle</string></code>
 +
 +===== orientation =====
 +
 +Orientation to attach resource to collider in degrees.
 +
 +  * Full name: ''touchSensor.orientation'' or ''touchSensor({id}).orientation''
 +  * Type: 3-component float vector
 +  * Default Value: (0,0,0)
 +  * Example (*.deeclass) <code xml><vector name='touchSensor.orientation' x='30' y='0' z='0'/></code>
 +
 +===== position =====
 +
 +Position to attach resource to collider.
 +
 +  * Full name: ''touchSensor.position'' or ''touchSensor({id}).position''
 +  * Type: 3-component float vector
 +  * Default Value: (0,0,0)
 +  * Example (*.deeclass) <code xml><vector name='touchSensor.position' x='0' y='0' z='0.1'/></code>
  
 ===== shape ===== ===== shape =====
Line 58: Line 93:
   * Example (*.deeclass) <code xml><boolean name='touchSensor.touching'>false</boolean></code>   * Example (*.deeclass) <code xml><boolean name='touchSensor.touching'>false</boolean></code>
  
-===== position =====+====== Events ======
  
-Position to attach resource to collider.+===== elementEntered =====
  
-  * Full name: ''touchSensor.position'' or ''touchSensor({id}).position'' +Element entered touch sensor.
-  * Type: 3-component float vector +
-  * Default Value: (0,0,0) +
-  * Example (*.deeclass) <code xml><vector name='touchSensor.position' x='0' y='0' z='0.1'/></code>+
  
-===== orientation =====+===== elementLeft =====
  
-Orientation to attach resource to collider in degrees.+Element left touch sensor.
  
-  * Full name: ''touchSensor.orientation'' or ''touchSensor({id}).orientation'' +===== elementCanTouch =====
-  * Type: 3-component float vector +
-  * Default Value: (0,0,0) +
-  * Example (*.deeclass) <code xml><vector name='touchSensor.orientation' x='30' y='0' z='0'/></code>+
  
-===== bone =====+Element can touch this touch sensor if all listeners return true.
  
-Bone to attach resource to. If empty string attach to collider.+====== Behavior Tree Actions ======
  
-  * Full name: ''touchSensor.bone'' or ''touchSensor({id}).bone'' +This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''touchSensor'' with ''touchSensor(id)''.
-  * Type: string +
-  * Default Value: empty string +
-  * Example (*.deeclass) <code xml><string name='touchSensor.bone'>attach</string></code>+
  
-====== Events ======+===== touchSensor.set =====
  
-===== elementEntered =====+Set one or more touch sensor parameters.
  
-Element entered touch sensor.+^Parameter^Value^Description^ 
 +|collisionFilter.filter.set|string|Set named [[gamedev:collisionfiltering|collision filter]] filter mask bit.| 
 +|collisionFilter.filter.clear|string|Clear named [[gamedev:collisionfiltering|collision filter]] filter mask bit.| 
 +|enabled|''true'', ''false''|Enable touch sensor|
  
 +This is an example of using this action:
 +<code xml>
 +<action name='touchSensor.set'>
 +  <parameter name='enabled'>true</parameter>
 +</action>
 +</code>
  
-===== elementLeft =====+===== touchSensor.update =====
  
-Element left touch sensor.+Update touch sensor.
  
-===== elementCanTouch =====+^Parameter^Value^Description^ 
 +|touching.runEvent|string|Run state machine event on all touching elements supporting [[behavior_statemachine|ECBehaviorStateMachine]]|
  
-Element can touch this touch sensor if all listeners return true.+This is an example of using this action: 
 +<code xml> 
 +<action name='touchSensor.update'> 
 +  <parameter name='touching.runEvent'>effect.jump</parameter> 
 +</action> 
 +</code> 
 + 
 +===== touchSensor.check ===== 
 + 
 +Check one or more touch sensor parameters. Action succeeds if all parameter value matches their respective touch sensor parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a touch sensor parameter matches (or not). 
 + 
 +^Parameter^Value^Description^ 
 +|count|integer|Count of touching elements equals integer value| 
 +|count.not|integer|Count of touching elements does not equal integer value| 
 +|count.less|integer|Count of touching elements is less than integer value| 
 +|count.greater|integer|Count of touching elements is greater than integer value| 
 +|player|''true'', ''false''|Player is touching touch sensor| 
 +|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='touchSensor.check'> 
 +    <parameter name='player'>true</parameter> 
 +  </action> 
 +  <!-- actions here run only if player is touching touch sensor --> 
 +</sequence> 
 +</code> 
 + 
 +====== Behavior Tree Conditions ====== 
 + 
 +This behavior adds these behavior tree conditions if behavior tree is present. 
 + 
 +===== touchSensor.check ===== 
 + 
 +Check one or more touch sensor parameters. Conditions returns true if all parameter value match their respective touch sensor parameter. This condition is typically used to run an action or sequence of actions as long as touch sensor conditions are true. 
 + 
 +^Parameter^Value^Description^ 
 +|touchSensor.count|integer|Count of touching elements equals integer value| 
 +|touchSensor.count.not|integer|Count of touching elements does not equal integer value| 
 +|touchSensor.count.less|integer|Count of touching elements is less than integer value| 
 +|touchSensor.count.greater|integer|Count of touching elements is greater than integer value| 
 +|touchSensor.player|''true'', ''false''|Player is touching touch sensor| 
 + 
 +This is an example of using this condition: 
 +<code xml> 
 +<action name='myAction' id='doing something'> 
 +  <parameter name='touchSensor.player'>true</parameter> 
 +  <condition>touchSensor.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 ''touchSensor'' with ''touchSensor(id)''. 
 + 
 +===== touchSensor.entered ===== 
 + 
 +Element entered touch sensor. Element is send as event parameter. Use [[behavior_statemachine#eventelementupdate|eventParameter.update]] or [[behavior_statemachine#eventelementcheck|eventParameter.check]] to work with the element. 
 + 
 +===== touchSensor.left ===== 
 + 
 +Element left touch sensor. Element is send as event parameter. Use [[behavior_statemachine#eventelementupdate|eventParameter.update]] or [[behavior_statemachine#eventelementcheck|eventParameter.check]] to work with the element.
  
 ====== Required Behaviors ====== ====== Required Behaviors ======
Line 107: Line 213:
  
   * [[behavior_collider|ECBehaviorCollider]]: Attach to collider.   * [[behavior_collider|ECBehaviorCollider]]: Attach 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 ======
Line 149: Line 257:
      
   <behavior type='ECBehaviorTouchSensor'>   <behavior type='ECBehaviorTouchSensor'>
-    <!-- optional: set collision filter. default value '4:3' which means +    <!-- optional: use behavior tree with id instead of empty string --> 
-                   category BaseGameApp.CollisionFilterBit.trigger +    <string name='behaviorTree'>second</string> 
-                   filter BaseGameApp.CollisionFilterBit.actorAI. +     
-                   format is '', 'category' or 'category:filter' where category and filter +    <!-- optional: use state machine with id instead of empty string --> 
-                   are a list of bits to set. --> +    <string name='stateMachine'>second</string>
-    <string name='collisionFilter'>3:4 0</string>+
          
     <!-- set element properties. omit property prefix if used inside behavior tag -->     <!-- set element properties. omit property prefix if used inside behavior tag -->
dragengine/modules/dragonscript/behavior_touchsensor.1741884539.txt.gz · Last modified: by dragonlord