User Tools

Site Tools


dragengine:modules:dragonscript:behavior_bodytilting

ECBehaviorBodyTilting

behavior adding body tilting support for actors projected to ground.

Helps actors with appropriate animator setup to align their body to uneven ground underneath. This is done by using a set of collider collision tests to probe the terain. The result is handed over to a Locomotion insatance to calculate the tilting values. These values are then set to animator controlled linked to tilting values.

Behavior uses 4 collider collision tests located front-left, front-right, back-left and back-right.

To this behavior add it and either set the class properties or call setShape(), setOrigin() and setDirection() to initialize. Then use Locomotion.addControllerMapping() with Locomotion.ATTR_TILT_OFFSET, Locomotion.ATTR_TILT_VERTICAL and Locomotion.ATTR_TILT_HORIZONTAL for animators supporting tilting.

See also:

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix bodyTilting. .

testDirection

Set test direction. Defines the Y coordinate of the direction. X and Z coordinates are 0.

  • Full name: bodyTilting.testDirection
  • Type: float
  • Default Value: -0.6
  • Example (*.deeclass)
    <float name='bodyTilting.testDirection'>-0.8</float>

testOrigin

Set test origin. Used as setOrigin(x,z,y) hence right=x, front=z, up=y .

  • Full name: bodyTilting.testOrigin or bodyTilting({id}).testOrigin
  • Type: 3-component float vector
  • Default Value: (0.2,0.2,0.2)
  • Example (*.deeclass)
    <vector name='bodyTilting.testOrigin' x='0.3' y='0.3' z='0.3'/>

Events

This behavior can be used only once on an element.

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorBodyTilting.

Since DragonScript Module Version 1.0

Use Cases

  • Align actor with ground in a more sophisticated way than just using ground normal.

Element Class Example

This example defines an element which body tilting support.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorColliderAI colliderAI
  public var ECBehaviorLocomotion locomotion
  public var ECBehaviorProjectToGround projectToGround
  public var ECBehaviorBodyTilting bodyTilting
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    colliderAI = ECBehaviorColliderAI.new(this, collider)
    locomotion = ECBehaviorLocomotion.new(this, colliderAI)
    projectToGround = ECBehaviorProjectToGround.new(this, colliderAI)
    bodyTilting = ECBehaviorBodyTilting.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='ECBehaviorProjectToGround'/>
 
  <behavior type='ECBehaviorBodyTilting'>
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <float name='.testDirection'>-0.8</float>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorBodyTilting' id='second'/>
</elementClass>

Live Examples

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