User Tools

Site Tools


dragengine:modules:dragonscript:behavior_colliderai

This is an old revision of the document!


ECBehaviorColliderAI

Behavior element behavior adding collider support suitable for actor AI.

ECBehaviorColliderAI adds a collider which is useable for actor AI usage. This collider is not linked to ECBehaviorComponent but instead creates a ColliderVolume. The shape of the collider can be set manually or obtained from Rig resources. Using shapes from rig resources is usually the simpler way while creating shapes allows for greater flexibility. Otherwise the classes behave similar.

ECBehaviorColliderAI requires ECBehaviorCollider. Do not use this behavior if other behaviors try to move the ECBehaviorCollider. Doing so can produce strange results. Apply velocities and changes to the AI collider.

In contrary to ECBehaviorCollider this behavior does synchronize position with the element position but not vice versa. Actors typically have complex requirements on how their AI collider can move including projecting down to the ground after physics processing has finished. Behaviors suitable for managing collider AI typically update the AI collider velocities during think() and update element position and orientation from AI collider during postThink().

See also:

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix colliderAI. .

Events

This behavior has these events:

collisionResponse

Collision detected.

canHitCollider

Collision between colliders is possible. Only send if callback is enabled in collider AI. Stops after the first listener returning false. All listeneres added after this listener will not be called.

colliderChanged

Collider changed.

Behavior Tree Actions

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

colliderAI.set

Set one or more collider ai parameters.

ParameterValueDescription
enabledtrue, falseEnable collider
gravityvector3Set gravity
gravity.apply Apply gravity to linear velocity of collider
shapehumanoidSet collider shape. Requires additional parameters
shape.radiusfloatSet radius in meters of humanoid shape
shape.heightfloatSet height in meters of humanoid shape
geometryFromCollider Set element position and orientation from collider
stop.turning Clear angular velocity of collider
stop.moving Clear linear velocity of collider

This is an example of using this action:

<action name='colliderAI.set'>
  <parameter name='shape'>humanoid</parameter>
  <parameter name='shape.radius'>0.3</parameter>
  <parameter name='shape.height'>1.8</parameter>
</action>

colliderAI.collision

Handle collisions.

ParameterValueDescription
stop Stop collider from moving and turning. Prevents any further collision in this frame update.
sliding Applies sliding collision response

This is an example of using this action:

<action name='colliderAI.collision'>
  <parameter name='sliding'/>
</action>

colliderAI.check

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

ParameterValueDescription
enabledtrue, falseCollider is enabled
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='colliderAI.check'>
    <parameter name='enabled'>true</parameter>
  </action>
  <!-- actions here run only if collider ai is enabled -->
</sequence>

Behavior Tree Conditions

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

colliderAI.check

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

ParameterValueDescription
colliderAI.enabledtrue, falseCollider is enabled

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='colliderAI.enabled'>true</parameter>
  <condition>colliderAI.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

ECBehaviorColliderAI.

Since DragonScript Module Version 1.0

Use Cases

  • Allow actor to style his player actor using custom colors for individual body parts.
  • Create variations of NPCs by adding color slots that can be modified in XML Element Classes or using Stub Properties.

Element Class Example

This example defines an element which contains a resources.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorColliderAI colliderAI
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    colliderAI = ECBehaviorColliderAI.new(this, collider)
  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'>
    <!-- optional: set collision filter. default value '3:0 1 2 3 4' which means
                   category BaseGameApp.CollisionFilterBit.actorAI
                   filter BaseGameApp.CollisionFilterBit.geometry,
                          BaseGameApp.CollisionFilterBit.dynamic,
                          BaseGameApp.CollisionFilterBit.actorAI,
                          BaseGameApp.CollisionFilterBit.trigger.
                   format is '', 'category' or 'category:filter' where category and filter
                   are a list of bits to set. -->
    <string name='collisionFilter'>3:0 1 2 3 4</string>
 
    <!-- 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 -->
    <string name='.name'>value</string>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_colliderai.1746804774.txt.gz · Last modified: 2025/05/09 15:32 by dragonlord