Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » 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.
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 have the prefix forceField.
or forceField({id}).
if id is not empty.
Set influence area. Geometry touching this shape is affected by this force field.
forceField.influenceArea
or forceField({id}).influenceArea
<string name='forceField.influenceArea'>box:position,0,0.5,0:extends,2,1,0.5</string>
Set falloff radius. Geometry inside this distance from the border is faded out gradually.
forceField.radius
or forceField({id}).radius
<float name='forceField.radius'>2</float>
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.
forceField.exponent
or forceField({id}).exponent
<float name='forceField.exponent'>0.5</float>
Set field type.
forceField.fieldType
or forceField({id}).fieldType
Allowed Values:
Value | Description |
---|---|
radial | Force is applied radial from the center. |
linear | Force is applied along the force direction. |
vortex | Force is applied vortex like swirling around. |
radial
<string name='forceField.fieldType'>linear</string>
Set force application type.
forceField.applicationType
or forceField({id}).applicationType
Allowed Values:
Value | Description |
---|---|
direct | Apply force equally to all elements independend of shape. |
surface | Apply force on exposed surface area. |
mass | Apply force on mass. |
speed | Apply force relative to speed of element. |
direct
<string name='forceField.applicationType'>mass</string>
Set force direction.
forceField.direction
or forceField({id}).direction
<vector name='forceField.direction' x='0' y='1' z='0'/>
Set force in newton. Negative force reverse direction.
forceField.force
or forceField({id}).force
<float name='forceField.force'>50</float>
Set fluctuation of direction in degrees.
forceField.fluctuationDirection
or forceField({id}).fluctuationDirection
<float name='forceField.fluctuationDirection'>45</float>
Set force in newton. Negative force reverse direction.
forceField.fluctuationForce
or forceField({id}).fluctuationForce
<float name='forceField.fluctuationForce'>20</float>
Set force field enabled.
forceField.enabled
or forceField({id}).enabled
<boolean name='forceField.enabled'>false</boolean>
Set shape from which the force originates. If not set force originates from origin position.
forceField.shape
or forceField({id}).shape
<string name='forceField.shape'>box:position,0,0.5,0:extends,2,1,0.5</string>
Set position to attach resource to collider.
forceField.position
or forceField({id}).position
<vector name='forceField.position' x='0' y='0' z='0.1'/>
Set orientation to attach resource to collider in degrees.
forceField.orientation
or forceField({id}).orientation
<vector name='forceField.orientation' x='30' y='0' z='0'/>
Set bone to attach resource to. If empty string attach to collider.
forceField.bone
or forceField({id}).bone
<string name='forceField.bone'>attach</string>
Set trigger enabling force field. If no trigger is set the state of enabled
property is used.
forceField.trigger
or forceField({id}).trigger
enabled
<string name='forceField.trigger'>@switchOnVent & @powerEnabled</string>
This behavior supports these events:
Force field has been enabled.
Force field has been disabled.
Force field parameters changed.
This behavior requires no other behaviors.
This behavior does support element class to be persistable (setPersistable). Saves these states:
Since DragonScript Module Version 1.0
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
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>