Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorProjectToGround
Behavior element behavior adding project to ground support for actor AI.
Adds TouchSensor. The touch sensor is used to improve performance and requires a shape large enough to enclose the ECBehaviorColliderAI or ECBehaviorCollider (whichever is present) along all the up and down projection range. The touch sensor is attached to collider. The touch sensor uses the collision filter from collider.
To use this behavior add it to an actor. The behavior will run during postThink() and projects the actor position down to the ground if enabled. The grounded position is stored and can then be retrieved to work with. By default the behavior is set to automatically apply the grounded position to the actor. This behavior can be desibled for custome project to ground handling.
This behavior can be used only once on an element.
Element class properties have the prefix projectToGround.
.
Set apply projected position automatically to actor during postThink(). If disabled actor actions have to use getGroundedPosition() to place the actor.
projectToGround.applyToActor
<boolean name='projectToGround.applyToActor'>false</boolean>
This behavior has these events:
Enabled changed.
Actor switched between touching ground and not touching ground.
This behavior does not support optional behaviors.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which project to ground support.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorColliderAI colliderAI public var ECBehaviorProjectToGround projectToGround func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) colliderAI = ECBehaviorColliderAI.new(this, collider) projectToGround = ECBehaviorProjectToGround.new(this, colliderAI) 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='ECBehaviorProjectToGround'> <!-- set element properties. omit property prefix if used inside behavior tag --> <boolean name='.applyToActor'>false</boolean> </behavior> </elementClass>