{{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]] >> **ECBehaviorTouching** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorTouching ====== Behavior element behavior matching trigger target to touching sensor. Fires and resets a trigger target depending if elements are in touch sensor. Optionally pulses trigger target instead of just firing it. ====== Instance Counts ====== This behavior can be used multiple times on an element to add multiple triggers. Use the behavior identifier to tell them apart. ====== Element Class Properties ====== Element class properties have the prefix ''touching.'' or ''touching({id}).'' if id is not empty. ===== touchSensor.* ===== Behavior adds a child [[behavior_touchsensor|ECBehaviorTouchSensor]]. The child behavior has the identifier ''touchSensor'' or ''touchSensor({id})''. The properties of the child behavior have the prefix ''touching.touchSensor.'' or ''touching({id}).touchSensor.'' * Example (*.deeclass) box:position,0,0.5,0:extends,2,1,0.5 ===== target ===== Fires target if one or more elements touch the child touch sensor. Resets target as soon as no element touches the child touch sensor anymore. * Full name: ''touching.target'' or ''touching({id}).target'' * Type: string * Default Value: empty string * Example (*.deeclass) playerEntered ===== pulse ===== Pulse target instead of toggle fired state. Hence the first time an element touches the child touch sensor the target is pulsed. Nothing happens until the last element stops touching the child touch sensor. At that time the trigger is ready again to fire if an element touches the child touch sensor. * Full name: ''touching.pulse'' or ''touching({id}).pulse'' * Type: boolean * Default Value: ''false'' * Example (*.deeclass) true ====== Events ====== ===== startTouching ===== First element entered touch sensor. ===== stopTouching ========== Last element left touch sensor. ====== Behavior Tree Actions ====== The [[behavior_touchsensor|ECBehaviorTouchSensor]] behavior adds behavior tree actions if behavior tree is present. See [[behavior_touchsensor#behavior_tree_actions|ECBehaviorTouchSensor Behavior Tree Actions]]. Replace ''touchSensor'' with ''touching.touchSensor'' or ''touching(id).touchSensor''. This is an example of using touch sensor behavior tree actions: true true ====== Behavior Tree Conditions ====== The [[behavior_touchsensor|ECBehaviorTouchSensor]] behavior adds behavior tree conditions if behavior tree is present. See [[behavior_touchsensor#behavior_tree_conditions|ECBehaviorTouchSensor Behavior Tree Conditions]]. Replace ''touchSensor'' with ''touching.touchSensor'' or ''touching(id).touchSensor''. This is an example of using touch sensor behavior tree conditions: true touching.touchSensor.check ====== Required Behaviors ====== This behavior requires no other behaviors. ====== Optional Behaviors ====== * [[behavior_collider|ECBehaviorCollider]]: Attach child touch sensor to collider. * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use. ====== Persistency ====== This behavior does not required element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorTouching.html,ECBehaviorTouching~@#. Since DragonScript Module Version ''1.0'' ====== Use Cases ====== * Fire target if player touches element. * Enable an action as long as the player touches element. ====== Element Class Example ====== This example defines an element which fire target on elements touching. class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorTouching touching func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) touching = ECBehaviorTouching.new(this, collider) end end ====== Behavior Factory ====== Using element class supporting adding behaviors the behavior can be added like this: playerEntered ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]