User Tools

Site Tools


dragengine:modules:dragonscript:behavior_hitscan

ECBehaviorHitScan

Behavior adding hit-scan support to elements.

Behavior supports using one or more collider collision tests to do one or more hit scans for example to check for weapon projectile impacts. Hit scans are done once then the result can be examine. To use this behavior add ECBehaviorCollider then this behavior. The collider is used to carry the collision tests.

Instance Counts

This behavior can be used multiple times on an element to add multiple independent hit scans. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix hitScan. or hitScan({id}). if id is not empty.

range

Set test range.

  • Full name: hitScan.range or hitScan({id}).range
  • Type: float
  • Default Value: 20
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='hitScan.range'>0.5</float>

offset

Set test origin offset.

  • Full name: hitScan.offset or hitScan({id}).offset
  • Type: float
  • Default Value: 0
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='hitScan.offset'>0.5</float>

origin

Set test origin.

  • Full name: hitScan.origin or hitScan({id}).origin
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='hitScan.origin' x='0' y='0' z='0.2'/>

direction

Set test direction.

  • Full name: hitScan.direction or hitScan({id}).direction
  • Type: 3-component float vector
  • Default Value: (0,0,1)
  • Example (*.deeclass)
    <vector name='hitScan.direction' x='0' y='0' z='0.2'/>

orientation

Set test orientation.

  • Full name: hitScan.orientation or hitScan({id}).orientation
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='hitScan.orientation' x='20' y='0' z='0'/>

bone

Set test bone.

  • Full name: hitScan.bone or hitScan({id}).bone
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='hitScan.bone'>value</string>

Events

This behavior has no events

Required Behaviors

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable). Saves selected color.

API Documentation

ECBehaviorHitScan.

Since DragonScript Module Version 1.0

Use Cases

  • Line of sight tests.
  • Test if a weapon hits a target.

Element Class Example

This example defines an element which contains a hit scan.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorHitScan hitScan
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    hitScan = ECBehaviorHitScan.new(this, collider, component)
    hitScan.getRange().setValue(50)
  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='ECBehaviorHitScan'>
    <!-- optional: use component with id instead of empty string -->
    <string name='component'>second</string>
 
    <!-- optional: set collision filter. default value '1:0 1 2' which means
                   category BaseGameApp.CollisionFilterBit.dynamic
                   filter BaseGameApp.CollisionFilterBit.geometry,
                          BaseGameApp.CollisionFilterBit.dynamic,
                          BaseGameApp.CollisionFilterBit.actor.
                   format is '', 'category' or 'category:filter' where category and filter
                   are a list of bits to set. -->
    <string name='collisionFilter'>1:0 1 2</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <float name='.range'>50</float>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorHitScan' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_hitscan.txt · Last modified: 2025/03/12 19:36 by dragonlord