Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorForceField

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.

radius

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

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.

fieldType

Set field type.

applicationType

Set force application type.

direction

Set force direction.

force

Set force in newton. Negative force reverse direction.

fluctuationDirection

Set fluctuation of direction in degrees.

fluctuationForce

Set force in newton. Negative force reverse direction.

enabled

Set force field enabled.

shape

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

position

Set position to attach resource to collider.

orientation

Set orientation to attach resource to collider in degrees.

bone

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

trigger

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

Events

This behavior supports these events:

forceFieldEnabled

Force field has been enabled.

forceFieldDisabled

Force field has been disabled.

forceFieldParametersChanged

Force field parameters changed.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace forceField with forceField(id).

forceField.set

Set one or more force field parameters.

ParameterValueDescription
enabledtrue, falseEnable force field

This is an example of using this action:

<action name='forceField.set'>
  <parameter name='enabled'>true</parameter>
</action>

forceField.check

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

ParameterValueDescription
enabledtrue, falseForce field is enabled or not
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='forceField.check'>
    <parameter name='enabled'>true</parameter>
  </action>
  <!-- actions here run only if force field is enabled -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace forceField with forceField(id).

forceField.check

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

ParameterValueDescription
forceField.enabledtrue, falseForce field is enabled or not

This is an example of using this condition:

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

State Machine Actions

Same as Behavior Tree Actions.

State Machine Conditions

Same as Behavior Tree Conditions.

State Machine Events

This behavior sends these state machine events. If behavior has non-empty identifier replace forceField with forceField(id).

forceField.enabled

Force field has been enabled.

forceField.disabled

Force field has been disabled.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorForceField.

Since DragonScript Module Version 1.0

Use Cases

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>
 
    <!-- optional: identifier of ECBehaviorTriggered to synchronize with or empty
                   string to not synchronize. default is empty string. -->
    <string name='trigger.synchronize'>other</string>
 
    <!-- optional: add behavior trees. default adds all behavior trees. -->
    <list name='behaviorTrees'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
 
    <!-- optional: add state machines. default adds all state machines. -->
    <list name='stateMachines'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
 
    <!-- 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