User Tools

Site Tools


dragengine:modules:dragonscript:behavior_touching

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 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)
    <string name='touching.touchSensor.shape'>box:position,0,0.5,0:extends,2,1,0.5</string>

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)
    <string name='touching.target'>playerEntered</string>

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)
    <boolean name='touching.pulse'>true</boolean>

Events

startTouching

First element entered touch sensor.

stopTouching

Last element left touch sensor.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does not required element class to be persistable (setPersistable).

API Documentation

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:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorTouching'>
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.target'>playerEntered</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorTouching' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_touching.txt · Last modified: 2025/03/13 17:17 by dragonlord