User Tools

Site Tools


dragengine:modules:dragonscript:behavior_clearpath

ECBehaviorClearPath

Behavior in action

Behavior adding support to actors to make other actors get out of the way.

This behavior is useful for situations where actors can get in the way of the player or other actors. The behavior uses a collider collision test along the movement direction to periodically check for obstacles. If an obstacle is detected and it has ECBehaviorStepAside support it is told to step aside if possible.

This behavior can be used together with ECBehaviorAvoidCollision but the two can potentially affect each other depending on the configuration used for this behavior. Should this happen either adjust the configuration or make sure only one behavior is enabled at each time.

This behavior can be disabled temporarily.

To use this behavior add it to the element class and make sure to call setShapeSphere() 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.

Configurations

There are usually two possible configurations used for this behavior.

The first configuration applies to short distances only. In this configuration the check interval is around 1s or lower and the clear path time is around 0.05s. This results in the actor clearing the path up ahead of only 0.06m (assuming a walk speed of 1.25 m/s). This configuration results in the actor clearing path only if he is nearly bumping into other actors. The advantage of this configuration is that actors do not move away other actors when approaching them but still moves them away if blocking the path. This configuration works best if you just want to ensure actors can not block the path of other actors without needing them to have a clear path a long distance ahead.

The second configuration applies to long distance clearing of path. In this configuration the check interval is around 1s and the clear path time is around 2s. This results in the actor clearing the path up ahead to 2.5m (assuming a walk speed of 1.25 m/s). In this configuration the actor usually does not get in contact with actors standing in his way. The downside is though actors trying to approach other actors. In this case they are easily made stepping aside which is not always what you want.

For most situations the first configuration is the one to choose since it prevents the actor-actor stuck problems while exhibiting the least side effects. The second configuration though can be insteresting to switch to if actors need a clear path for example while running away. For this reason the first configuration is used as default.

Instance Counts

This behavior can be used only once on an element. The behavior always has identifier empty string.

Element Class Properties

Element class properties have the prefix clearPath. .

enabled

Determines if the behavior is initially enabled.

  • Full name: clearPath.enabled
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='clearPath.enabled'>false</boolean>

checkInterval

Check interval in seconds.

  • Full name: clearPath.checkInterval
  • Type: floating point
  • Default value: 1
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='clearPath.checkInterval'>0.5</float>

clearPathTime

Clear path time in seconds indicating how far ahead the actors clear path.

  • Full name: “clearPath.clearPathTime”
  • Type: floating point
  • Default value: 0.05
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='clearPath.clearPathTime'>1.5</float>

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present.

clearPath.set

Set one or more clear path parameters.

ParameterValueDescription
enabledtrue, falseEnable clear path
check.intervalfloatCheck interval in seconds
check.timerfloatCheck timer in seconds. Typically 0 to reset timer
clearPath.timefloatClear path time in seconds indicating how far ahead the actors clear path

This is an example of using this action:

<action name='clearPath.set'>
  <parameter name='enabled'>true</parameter>
</action>

clearPath.check

Check one or more clear path parameters. Action succeeds if all parameter value matches their respective clear path parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a clear path parameter matches (or not).

ParameterValueDescription
enabledtrue, falseClear path is enabled or not
check.interval.lessfloatCheck interval is less then value seconds
check.interval.greaterfloatCheck interval is greater then value seconds
check.timer.lessfloatCheck timer is less then value seconds
check.timer.greaterfloatCheck timer is greater then value seconds
clearPath.time.lessfloatClear path time is less then value seconds
clearPath.time.greaterfloatClear path time is greater then 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:

<sequence>
  <action name='clearPath.check'>
    <parameter name='enabled'>true</parameter>
  </action>
  <!-- actions here run only if clear path is enabled -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present.

clearPath.check

Check one or more clear path parameters. Conditions returns true if all parameter value match their respective clear path parameter. This condition is typically used to run an action or sequence of actions as long as clear path conditions are true.

ParameterValueDescription
clearPath.enabledtrue, falseClear path is enabled or not
clearPath.check.interval.lessfloatCheck interval is less then value seconds
clearPath.check.interval.greaterfloatCheck interval is greater then value seconds
clearPath.check.timer.lessfloatCheck timer is less then value seconds
clearPath.check.timer.greaterfloatCheck timer is greater then value seconds
clearPath.clearPath.time.lessfloatClear path time is less then value seconds
clearPath.clearPath.time.greaterfloatClear path time is greater then value seconds

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='clearPath.enabled'>true</parameter>
  <condition>clearPath.check</condition>
</action>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends no state machine events.

Required Behaviors

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorClearPath.

Since DragonScript Module Version 1.4

Use Cases

  • Avoid actors blocking the path of other actors. The moving actors can make blocking actors move away.
  • Avoid player blocking actors or actors blocking the player.
  • Create situations where player or other actors are running and other actors move out of the way ahead of time.

Element Class Example

class ExampleElementClass extends BehaviorElementClass
   public var ECBehaviorComponent component
   public var ECBehaviorCollider collider
   public var ECBehaviorColliderAI colliderAI
   public var ECBehaviorLocomotion locomotion
   public var ECBehaviorClearPath clearPath
   
   public func new() super("ExampleElement")
     component = ECBehaviorComponent.new(this)
     collider = ECBehaviorCollider.new(this, component)
     colliderAI = ECBehaviorColliderAI.new(this, collider)
     locomotion = ECBehaviorLocomotion.new(this, colliderAI)
     clearPath = ECBehaviorClearPath.new(this, locomotion)
   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='ECBehaviorColliderAI'/>
  <behavior type='ECBehaviorLocomotion'/>
 
  <behavior type='ECBehaviorClearPath'>
    <!-- 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='.checkInterval'>1.5</float>
  </behavior>
</elementClass>

Live Examples

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