User Tools

Site Tools


dragengine:modules:dragonscript:behavior_forcefield

ECBehaviorForceField

Behavior element behavior adding force field support.

Behavior adds a ForceField resource to the the behavior element. Force fields apply physical forces to physical elements in the game world if their collision filter to match.

If the ECBehaviorCollider behavior is present in the behavior element before this behavior is added the force field is attached. The force field is attached to the named bone if defined otherwise it is attached statically.

Instance Counts

This behavior can be used multiple times on an element to add multiple force fields to mainpulate. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix forceField. or forceField({id}). if id is not empty.

influenceArea

Set influence area. Geometry touching this shape is affected by this force field.

  • Full name: forceField.influenceArea or forceField({id}).influenceArea
  • Type: string (shape format). See “Shape List Encoding” in CodecPropertyString.
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='forceField.influenceArea'>box:position,0,0.5,0:extends,2,1,0.5</string>

radius

Set falloff radius. Geometry inside this distance from the border is faded out gradually.

  • Full name: forceField.radius or forceField({id}).radius
  • Type: float
  • Default Value: 0
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='forceField.radius'>2</float>

exponent

Set falloff exponent. Shape of the fading out applied due to radius. Value of 1 represents linear fading. Values less than 1 fade of stronger near the border. Values greater than 1 fade of stronger near the inner border.

  • Full name: forceField.exponent or forceField({id}).exponent
  • Type: float
  • Default Value: 1
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='forceField.exponent'>0.5</float>

fieldType

Set field type.

  • Full name: forceField.fieldType or forceField({id}).fieldType
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    radialForce is applied radial from the center.
    linearForce is applied along the force direction.
    vortexForce is applied vortex like swirling around.
  • Default Value: radial
  • Example (*.deeclass)
    <string name='forceField.fieldType'>linear</string>

applicationType

Set force application type.

  • Full name: forceField.applicationType or forceField({id}).applicationType
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    directApply force equally to all elements independend of shape.
    surfaceApply force on exposed surface area.
    massApply force on mass.
    speedApply force relative to speed of element.
  • Default Value: direct
  • Example (*.deeclass)
    <string name='forceField.applicationType'>mass</string>

direction

Set force direction.

  • Full name: forceField.direction or forceField({id}).direction
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='forceField.direction' x='0' y='1' z='0'/>

force

Set force in newton. Negative force reverse direction.

  • Full name: forceField.force or forceField({id}).force
  • Type: float
  • Default Value: 1
  • Example (*.deeclass)
    <float name='forceField.force'>50</float>

fluctuationDirection

Set fluctuation of direction in degrees.

  • Full name: forceField.fluctuationDirection or forceField({id}).fluctuationDirection
  • Type: float
  • Default Value: 0
  • Example (*.deeclass)
    <float name='forceField.fluctuationDirection'>45</float>

fluctuationForce

Set force in newton. Negative force reverse direction.

  • Full name: forceField.fluctuationForce or forceField({id}).fluctuationForce
  • Type: float
  • Default Value: 0
  • Example (*.deeclass)
    <float name='forceField.fluctuationForce'>20</float>

enabled

Set force field enabled.

  • Full name: forceField.enabled or forceField({id}).enabled
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='forceField.enabled'>false</boolean>

shape

Set shape from which the force originates. If not set force originates from origin position.

  • Full name: forceField.shape or forceField({id}).shape
  • Type: string (shape format). See “Shape List Encoding” in CodecPropertyString.
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='forceField.shape'>box:position,0,0.5,0:extends,2,1,0.5</string>

position

Set position to attach resource to collider.

  • Full name: forceField.position or forceField({id}).position
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='forceField.position' x='0' y='0' z='0.1'/>

orientation

Set orientation to attach resource to collider in degrees.

  • Full name: forceField.orientation or forceField({id}).orientation
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='forceField.orientation' x='30' y='0' z='0'/>

bone

Set bone to attach resource to. If empty string attach to collider.

  • Full name: forceField.bone or forceField({id}).bone
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='forceField.bone'>attach</string>

trigger

Set trigger enabling force field. If no trigger is set the state of enabled property is used.

  • Full name: forceField.trigger or forceField({id}).trigger
  • Type: string
  • Default Value: state of enabled
  • Example (*.deeclass)
    <string name='forceField.trigger'>@switchOnVent & @powerEnabled</string>

Events

This behavior supports these events:

forceFieldEnabled

Force field has been enabled.

forceFieldDisabled

Force field has been disabled.

forceFieldParametersChanged

Force field parameters changed.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable). Saves these states:

  • enabled

API Documentation

ECBehaviorForceField.

Since DragonScript Module Version 1.0

Use Cases

  • Allow element to apply physical forces to other elements using a force field.

Element Class Example

This example defines an element which contains a force field.

class MyElement extends BehaviorElementClass
  public var ECBehaviorCollider collider
  public var ECBehaviorForceField forceField
  func new()
    collider = ECBehaviorCollider.new(this, null)
    forceField = ECBehaviorForceField.new(this, collider)
    forceField.getForceField().getForce().setValue(50)
    forceField.getAttach().getPosition().setVector(Vector.new(0, 0, 0.3))
  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='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorForceField'>
    <!-- optional: set collision filter. default value '6:0 1 2 3 5' which means
                   category BaseGameApp.CollisionFilterBit.forceField
                   filter BaseGameApp.CollisionFilterBit.geometry,
                          BaseGameApp.CollisionFilterBit.dynamic,
                          BaseGameApp.CollisionFilterBit.actor,
                          BaseGameApp.CollisionFilterBit.actorAI,
                          BaseGameApp.CollisionFilterBit.particle.
                   format is '', 'category' or 'category:filter' where category and filter
                   are a list of bits to set. -->
    <string name='collisionFilter'>6:0 1 2 3 5</string>
 
    <!-- optional: use BaseGameApp trigger table. game can add more
                   supported values. default value is 'default' -->
    <string name='triggerTable'>default</string>
 
    <!-- optional: sync trigger with force field matching identifier -->
    <string name='syncTrigger'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <float name='.force'>50</float>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorForceField' id='second'/>
</elementClass>

Live Examples

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