{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorForceField**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== 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 [[behavior_collider|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) box:position,0,0.5,0:extends,2,1,0.5
===== 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) 2
===== 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) 0.5
===== fieldType =====
Set field type.
* Full name: ''forceField.fieldType'' or ''forceField({id}).fieldType''
* Type: enumeration
* 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.|
* Default Value: ''radial''
* Example (*.deeclass) linear
===== applicationType =====
Set force application type.
* Full name: ''forceField.applicationType'' or ''forceField({id}).applicationType''
* Type: enumeration
* 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.|
* Default Value: ''direct''
* Example (*.deeclass) mass
===== direction =====
Set force direction.
* Full name: ''forceField.direction'' or ''forceField({id}).direction''
* Type: 3-component float vector
* Default Value: (0,0,0)
* Example (*.deeclass)
===== force =====
Set force in newton. Negative force reverse direction.
* Full name: ''forceField.force'' or ''forceField({id}).force''
* Type: float
* Default Value: 1
* Example (*.deeclass) 50
===== fluctuationDirection =====
Set fluctuation of direction in degrees.
* Full name: ''forceField.fluctuationDirection'' or ''forceField({id}).fluctuationDirection''
* Type: float
* Default Value: 0
* Example (*.deeclass) 45
===== fluctuationForce =====
Set force in newton. Negative force reverse direction.
* Full name: ''forceField.fluctuationForce'' or ''forceField({id}).fluctuationForce''
* Type: float
* Default Value: 0
* Example (*.deeclass) 20
===== enabled =====
Set force field enabled.
* Full name: ''forceField.enabled'' or ''forceField({id}).enabled''
* Type: boolean
* Default Value: true
* Example (*.deeclass) false
===== 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) box:position,0,0.5,0:extends,2,1,0.5
===== 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)
===== 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)
===== 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) attach
===== 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) @switchOnVent & @powerEnabled
====== 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 ======
* [[behavior_collider|ECBehaviorCollider]]: Attach force field to collider.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable). Saves these states:
* enabled
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorForceField.html,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:
6:0 1 2 3 5
default
second
50
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]