User Tools

Site Tools


dragengine:modules:dragonscript:behavior_actormoverunstuck

ECBehaviorActorMoverUnstuck

Behavior adding support to unstuck actors moved by ECBehaviorActorMover.

This behavior helps in situations where an actor moving along a path ends up in a stuck position. This can happen due to other behaviors like ECBehaviorAvoidCollision trying to avoid obstacles as well as due to game events pushing the actor into unfavorable positions.

This behavior attaches to ECBehaviorActorMover to track if actor is moving. If the actor is moving the position of the actor is examined after an interval. If the position does not change by a threshold amount relative to the last tracked position the actor is considered stuck and ECBehaviorActorMover.updatePath() is called to calculate a new path.

The default interval is 3 seconds. The threshold is factor multiplied by the distance the actor would travel unobstructed using the movement speed set in ECBehaviorActorMover. The default threshold is 0.2 (20% of expected movement distance).

These parameters can be adjusted to match the actors.

This behavior can be temporarily disabled at runtime if required. By default the behavior is enabled.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix actorMoverUnstuck. .

interval

Set update interval in seconds.

  • Full name: actorMoverUnstuck.interval
  • Type: float
  • Default Value: 3
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='actorMoverUnstuck.interval'>2</float>

threshold

Set distance threshold. Threshold is percentage of distance.

  • Full name: actorMoverUnstuck.threshold
  • Type: float
  • Default Value: 0.2
  • Restriction: At least 0 and at most 1
  • Example (*.deeclass)
    <float name='actorMoverUnstuck.threshold'>0.3</float>

Events

This behavior has no events.

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorActorMoverUnstuck.

Since DragonScript Module Version 1.19

Use Cases

  • Free actor if it manages to get stuck.

Element Class Example

This example defines an element which can unstuck itself.

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 ECBehaviorActorMoverUnstuck actorMoverUnstuck
  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)
    actorMoverUnstuck = ECBehaviorActorMoverUnstuck.new(this, actorMover)
  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='ECBehaviorNavigator'/>
  <behavior type='ECBehaviorProjectToGround'/>
  <behavior type='ECBehaviorRideOn'/>
  <behavior type='ECBehaviorActorMover'/>
 
  <behavior type='ECBehaviorActorMoverUnstuck'>
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <float name='.interval'>2</float>
  </behavior>
</elementClass>

Live Examples

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