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.

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>
 
    <!-- 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