{{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]] >> **ECBehaviorHitScan** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== 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) 0.5 ===== offset ===== Set test origin offset. * Full name: ''hitScan.offset'' or ''hitScan({id}).offset'' * Type: float * Default Value: 0 * Restriction: At least 0 * Example (*.deeclass) 0.5 ===== origin ===== Set test origin. * Full name: ''hitScan.origin'' or ''hitScan({id}).origin'' * Type: 3-component float vector * Default Value: (0,0,0) * Example (*.deeclass) ===== direction ===== Set test direction. * Full name: ''hitScan.direction'' or ''hitScan({id}).direction'' * Type: 3-component float vector * Default Value: (0,0,1) * Example (*.deeclass) ===== orientation ===== Set test orientation. * Full name: ''hitScan.orientation'' or ''hitScan({id}).orientation'' * Type: 3-component float vector * Default Value: (0,0,0) * Example (*.deeclass) ===== bone ===== Set test bone. * Full name: ''hitScan.bone'' or ''hitScan({id}).bone'' * Type: string * Default Value: empty string * Example (*.deeclass) value ====== Events ====== This behavior has no events ====== Behavior Tree Actions ====== This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''hitScan'' with ''hitScan(id)''. ===== hitScan.start ===== Start hit scans. ^Parameter^Value^Description^ |type|''circular'', ''cone'', ''rectangular'', ''rectangular.uniform''|Distribution shape of tests. * ''circular'': Tests are arranged in a circular pattern. Set angle using ''angle'' * ''cone'': Tests are arranged randomly in a small cone cap. Set count using ''count''. Set angle using ''angle''. Useful for example for weapons with multiple projectiles like buck shots * ''rectangular'': Tests are arranged randomly across a small sphere segment. Set count using ''count''. Set angle using ''angle.horizontal'' and ''angle.vertical''. Useful for example for weapons with rectangular spreads like a duckbill modification * ''rectangular.uniform'': Tests are arranged uniformly across a small sphere segment. Set count using ''count.horizontal'' and ''count.vertical''. Set angle using ''angle.horizontal'' and ''angle.vertical''. Useful for example for weapons with rectangular spreads like a duckbill modification | |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: cone 10 5 ===== hitScan.stop ===== 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: ===== hitScan.check ===== 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: false 0.5 ====== Behavior Tree Conditions ====== This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''hitScan'' with ''hitScan(id)''. ===== hitScan.check ===== 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: false 0.5 hitScan.check ====== 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 ''hitScan'' with ''hitScan(id)''. ===== hitScan.done ===== Hit scan finished and the results can be examine now. ====== Required Behaviors ====== * [[behavior_collider|ECBehaviorCollider]]: Collider to attach tests to. ====== Optional Behaviors ====== * [[behavior_component|ECBehaviorComponent]]: Required if collision test has to originate from bone. * [[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 ====== This behavior does support element class to be persistable (setPersistable). Saves selected color. ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorHitScan.html,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: second 1:0 1 2 second second 50 ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]