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.

Required Behaviors

Optional Behaviors

This behavior does not support 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'>
    <!-- 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/03/12 19:40 by dragonlord