Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » 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.
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 have the prefix hitScan.
or hitScan({id}).
if id is not empty.
Set test range.
hitScan.range
or hitScan({id}).range
<float name='hitScan.range'>0.5</float>
Set test origin offset.
hitScan.offset
or hitScan({id}).offset
<float name='hitScan.offset'>0.5</float>
Set test origin.
hitScan.origin
or hitScan({id}).origin
<vector name='hitScan.origin' x='0' y='0' z='0.2'/>
Set test direction.
hitScan.direction
or hitScan({id}).direction
<vector name='hitScan.direction' x='0' y='0' z='0.2'/>
Set test orientation.
hitScan.orientation
or hitScan({id}).orientation
<vector name='hitScan.orientation' x='20' y='0' z='0'/>
Set test bone.
hitScan.bone
or hitScan({id}).bone
<string name='hitScan.bone'>value</string>
This behavior has no events
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace hitScan
with hitScan(id)
.
Start hit scans.
Parameter | Value | Description |
---|---|---|
type | circular , cone , rectangular , rectangular.uniform | Distribution shape of tests.
|
count | integer | Count of collision tests to start |
count.horizontal | integer | Horizontal count of collision tests to start |
count.vertical | integer | Vertical count of collision tests to start |
angle | float | Opening angle in degrees (angle across diameter) |
angle.horizontal | float | Horizontal opening angle in degrees (angle across width) |
angle.vertical | float | Vertical opening angle in degrees (angle across height) |
This is an example of using this action:
<action name='hitScan.start'> <parameter name='type'>cone</parameter> <parameter name='count'>10</parameter> <parameter name='angle'>5</parameter> </action>
Stop hit scans.
Parameter | Value | Description |
---|---|---|
clear | Clear hit results as if no hit has been done |
This is an example of using this action:
<action name='hitScan.stop'> <parameter name='clear'/> </action>
Check one or more hit scan parameters. Action succeeds if all parameter value matches their respective hit scan parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a hit scan parameter matches (or not).
Parameter | Value | Description |
---|---|---|
running | true , false | Hit scans are running |
hits | integer | Count of hits equals integer value |
hits.not | integer | Count of hits does not equal integer value |
hits.less | integer | Count of hits is less than integer value |
hits.greater | integer | Count of hits is greater than integer value |
hits.percentage.less | integer | Percentage of hits is less than value in the range from 0 to 1 |
hits.percentage.greater | integer | Percentage of hits is greater than value in the range from 0 to 1 |
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:
<sequence> <action name='hitScan.check'> <parameter name='running'>false</parameter> <parameter name='hits.percentage.greater'>0.5</parameter> </action> <!-- actions here run only if hit scans finished and more than 50% hits have been found --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace hitScan
with hitScan(id)
.
Check one or more hit scan parameters. Conditions returns true if all parameter value match their respective hit scan parameter. This condition is typically used to run an action or sequence of actions as long as hit scan conditions are true.
Parameter | Value | Description |
---|---|---|
hitScan.running | true , false | Hit scans are running |
hitScan.hits | integer | Count of hits equals integer value |
hitScan.hits.not | integer | Count of hits does not equal integer value |
hitScan.hits.less | integer | Count of hits is less than integer value |
hitScan.hits.greater | integer | Count of hits is greater than integer value |
hitScan.hits.percentage.less | integer | Percentage of hits is less than value in the range from 0 to 1 |
hitScan.hits.percentage.greater | integer | Percentage of hits is greater than value in the range from 0 to 1 |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='hitScan.running'>false</parameter> <parameter name='hitScan.hits.percentage.greater'>0.5</parameter> <condition>hitScan.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends these state machine events. If behavior has non-empty identifier replace hitScan
with hitScan(id)
.
Hit scan finished and the results can be examine now.
This behavior does support element class to be persistable (setPersistable). Saves selected color.
Since DragonScript Module Version 1.0
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
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> <!-- 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 --> <float name='.range'>50</float> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorHitScan' id='second'/> </elementClass>