Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » 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.
This behavior can be used only once on an element.
Element class properties have the prefix actorMoverUnstuck.
.
Set update interval in seconds.
actorMoverUnstuck.interval
<float name='actorMoverUnstuck.interval'>2</float>
Set distance threshold. Threshold is percentage of distance.
actorMoverUnstuck.threshold
<float name='actorMoverUnstuck.threshold'>0.3</float>
This behavior has no events.
This behavior does not support optional behaviors.
This behavior does not required element class to be persistable (setPersistable).
Since DragonScript Module Version 1.19
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
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>