User Tools

Site Tools


dragengine:modules:dragonscript:behavior_projecttoground

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.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix projectToGround. .

applyToActor

Set apply projected position automatically to actor during postThink(). If disabled actor actions have to use getGroundedPosition() to place the actor.

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

Events

This behavior has these events:

enabledChanged

Enabled changed.

touchesGroundChanged

Actor switched between touching ground and not touching ground.

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorProjectToGround.

Since DragonScript Module Version 1.0

Use Cases

  • Project actor down to ground if in reach.

Element Class Example

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

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='ECBehaviorProjectToGround'>
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <boolean name='.applyToActor'>false</boolean>
  </behavior>
</elementClass>

Live Examples

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