User Tools

Site Tools


dragengine:modules:dragonscript:behavior_rideon

ECBehaviorRideOn

Behavior adding support to actors to ride on ECBehaviorRidable.

If ECBehaviorProjectToGround and ECBehaviorColliderAI are enabled sets the ridable to the ground element if element supports ECBehaviorRidable. Otherwise clears the ridable.

Sometimes it is necessary to prevent the ridable to change although it usually would. This can be for example if an actor interacts with an object like sitting on a chair. Projecting to ground usually has to be disabled in this case to prevent the actor climbing on the chair instead of sitting on it. In general this is not a problem since the actor is usually not riding on another element. If tough the actor does ride on another element disabling projecting to ground will clear the ridable. This in turn causes the element to no more move together with the ridable element causing issues. To prevent this problem the ridable can be locked using setLocked(). While locked changes due to ECBehaviorProjectToGround changes will not cause setRidable() to be called. While locked you can still manually call setRidable() to assign a ridable of your choice.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix rideOn. .

Events

This behavior has these events:

ridableChanged

Ridable changed. Element begins or stops touching a ECBehaviorRidable.

Behavior Tree Actions

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

rideOn.check

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

ParameterValueDescription
ridabletrue, falseRiding on an element
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='rideOn.check'>
    <parameter name='ridable'>true</parameter>
  </action>
  <!-- actions here run only if riding on an element -->
</sequence>

Behavior Tree Conditions

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

rideOn.check

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

ParameterValueDescription
rideOn.ridabletrue, falseRiding on an element

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='rideOn.ridable'>true</parameter>
  <condition>rideOn.check</condition>
</action>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends these state machine events.

rideOn.begin

Element is riding on a ridable while previously it did not ride on a ridable.

rideOn.end

Element is not riding on a ridable while previously it has been riding on a ridable.

Required Behaviors

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorRideOn.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element which can ride on other elements.

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
  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)
  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'>
    <!-- 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_rideon.txt · Last modified: 2025/05/04 13:45 by dragonlord