{{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]] >> **ECBehaviorAvoidCollision**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorAvoidCollision ======
Behavior adding support to actors to avoid collisions with [[behavior_avoidedbyactor|ECBehaviorAvoidedByActor]].
Behavior attaches to [[behavior_actormover|ECBehaviorActorMover]] to modify walking path while moving.
To use this behavior add it to the element class and make sure to call setShapesSphere() to set up the collision test shapes. The best time to do this is either in BehaviorElement.init() or inside BaseActorAction if you need to change them per action.
See also:
* [[gamedev:colliders|Colliders]]
====== Instance Counts ======
This behavior can be used only once on an element.
====== Element Class Properties ======
Element class properties have the prefix ''avoidCollision.'' .
===== radius =====
Set avoid radius in meters.
* Full name: ''avoidCollision.radius''
* Type: float
* Default Value: 0.4
* Restriction: At least 0
* Example (*.deeclass) 0.6
====== Events ======
This behavior has no events.
====== Behavior Tree Actions ======
This behavior adds these behavior tree actions if behavior tree is present.
===== avoidCollision.set =====
Set one or more force field parameters.
^Parameter^Value^Description^
|waitBehindObstacles|''true'', ''false''|Wait behind obstacles instead of moving around them|
|enabled|''true'', ''false''|Enable avoid collision|
This is an example of using this action:
true
===== avoidCollision.stop =====
Stop avoiding collision.
This is an example of using this action:
===== avoidCollision.check =====
Check one or more force field parameters. Action succeeds if all parameter value matches their respective force field parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a force field parameter matches (or not).
^Parameter^Value^Description^
|waitBehindObstacles|''true'', ''false''|Wait behind obstacles instead of moving around them|
|enabled|''true'', ''false''|Avoid collision is enabled or not|
|avoiding|''true'', ''false''|In progress of avoiding a collision|
|avoiding.time.less|float|Ramining time avoiding collision is less than value seconds|
|avoiding.time.greater|float|Ramining time avoiding collision is greater than value seconds|
|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:
true
====== Behavior Tree Conditions ======
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''avoidCollision'' with ''avoidCollision(id)''.
===== avoidCollision.check =====
Check one or more force field parameters. Conditions returns true if all parameter value match their respective force field parameter. This condition is typically used to run an action or sequence of actions as long as force field conditions are true.
^Parameter^Value^Description^
|avoidCollision.waitBehindObstacles|''true'', ''false''|Wait behind obstacles instead of moving around them|
|avoidCollision.enabled|''true'', ''false''|Avoid collision is enabled or not|
|avoidCollision.avoiding|''true'', ''false''|In progress of avoiding a collision|
|avoidCollision.avoiding.time.less|float|Ramining time avoiding collision is less than value seconds|
|avoidCollision.avoiding.time.greater|float|Ramining time avoiding collision is greater than value seconds|
This is an example of using this condition:
true
avoidCollision.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.
===== avoidCollision.avoid =====
Avoid collision.
===== avoidCollision.stop =====
Stop avoiding collision.
====== Required Behaviors ======
* [[behavior_actormover|ECBehaviorActorMover]]
====== Optional Behaviors ======
* [[behavior_rideon|ECBehaviorRideOn]]: Avoid while respecting ground movement.
* [[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).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorAvoidCollision.html,ECBehaviorAvoidCollision~@#.
Since DragonScript Module Version ''1.0''
====== Use Cases ======
* Make actor avoid elements supporting [[behavior_avoidedbyactor|ECBehaviorAvoidedByActor]].
====== Element Class Example ======
This example defines an element which can avoid collisions.
class MyElement extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorColliderAI colliderAI
public var ECBehaviorLocomotion locomotion
public var ECBehaviorNavigator navigator
public var ECBehaviorProjectToGround projectToGround
public var ECBehaviorRideOn rideOn
public var ECBehaviorActorMover actorMover
public var ECBehaviorAvoidCollision avoidCollision
func new()
component = ECBehaviorComponent.new(this, null)
collider = ECBehaviorCollider.new(this, component)
colliderAI = ECBehaviorColliderAI.new(this, collider)
locomotion = ECBehaviorLocomotion.new(this, colliderAI)
navigator = ECBehaviorNavigator.new(this)
projectToGround = ECBehaviorProjectToGround.new(this, colliderAI)
rideOn = ECBehaviorRideOn.new(this, locomotion, projectToGround)
actorMover = ECBehaviorActorMover.new(this, locomotion, navigator, rideOn)
actorMover.setConversationActor(conversationActor)
avoidCollision = ECBehaviorAvoidCollision.new(this, actorMover, rideOn)
end
end
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
3:0 1 2 3
second
second
0.6
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]