Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorLightAnimation
Behavior element behavior adding animation support to ECBehaviorLight
This behavior modifies the light parameters of ECBehaviorLight instances present in the element using move keyframes stored in an Animation
or ECBehaviorComponent state. Animation playback starts when the light becomes activated and stops (and resets) if reactivated.
To use this behavior add first an ECBehaviorLight. Adding ECBehaviorLightAnimation
will then register itself as listener to the ECBehaviorLight and also set it to use custom light handling.
Using Animation
keyframes from a move is used to animate the light parameters.
Using ECBehaviorComponent the animated state is used to animate the light parameters. In this case the play time is 0 since the component state is typically driven by an animator or manually.
The input values obtained either from animation keyframes or component state is remapped before applying to the light parameter. This linearly maps the lower remap value (default 0
) to 0
output value and the upper remap value (default 1
) to 1
output value. Values outside the remap range are extrapolated.
Remapping is applied before scaling.
Multiple ECBehaviorLightAnimation
instances can be added to affect individual ECBehaviorLight instances like this example below.
class MyElement extends BehaviorElementClass func new() var ECBehaviorLight light1 = ECBehaviorLight.new(this) ECBehaviorLightAnimation.new(this, light1) var ECBehaviorLight light2 = ECBehaviorLight.new(this, "subLight") ECBehaviorLightAnimation.new(this, light2) end end
Element class properties have the prefix lightAnimation.
or lightAnimation({id}).
if id is not empty.
Set path to animation to use. Animation move based animation is used only if animation is set.
lightAnimation.animation
or lightAnimation({id}).animation
*.deanim
(all supported animation type modules)<string name='lightAnimation.animation'>light.deanim</string>
Set move name to use. Animation move based animation is used only if move is set.
lightAnimation.move
or lightAnimation({id}).move
<string name='lightAnimation.move'>flicker</string>
Set if animation playback is enabled.
lightAnimation.enabled
or lightAnimation({id}).enabled
<boolean name='lightAnimation.enabled'>false</boolean>
Set playback speed. Value of 1
plays back at normal speed. Values larger than 1 play back faster. Values less then 1 play back slower.
lightAnimation.playSpeed
or lightAnimation({id}).playSpeed
<float name='lightAnimation.playSpeed'>0.5</float>
Set enabled trigger. If no trigger is set the state of enabled
property is used.
lightAnimation.trigger
or lightAnimation({id}).trigger
enabled
<string name='lightAnimation.trigger'>@switchOnLight & @powerEnabled</string>
For each light parameter a set of properties can be defined. Replace <parameter>
with one of the values from the following list:
Value | Description |
---|---|
colorRed | Red light color. |
colorGreen | Green light color. |
colorBlue | Blue light color. |
intensity | Light intensity. |
range | Light range in meters. Beyond this range light has no effect. |
halfIntensityDistance | Light half intensity distance (0 to 1). At this position the light dropped to 50% strength. Allows to shape fall-off curve. A value of 0.1 is natural fall-off. Values larger than 0.1 make light fall off faster near the light source. Values smaller than 0.1 make light fall off faster near the light range. |
ambientRatio | Light ambient ratio (0 to 1). Percentage of total light to use as ambient light. |
spotAngle | Light spot angle in degrees (opening angle). |
spotRatio | Light spot ratio as height divided by width (0 to 1). Hence this is the aspect ratio of the spot light. |
spotSmoothness | Light spot smoothness (0 to 1). Percentage distance from border to center where light fall-off begins. A value of 0 produces constant light intensity across the entire spot cone. A value of 1 produces linear fade across the entire spot cone. |
spotExponent | Light spot exponent (0 or greater). Shape of light fall-off from spot center to spot border. A value of 1 is linear fall-off. Values larger than 0.1 make light fall off faster near the spot center. Values smaller than 0.1 make light fall off faster near the spot border. |
Set target to obtain value from. If <parameter>.parameter
is weight
target is the name of the vertex position set to use. Otherwise target is the name of the bone to use.
lightAnimation.<parameter>.target
or lightAnimation({id}).<parameter>.target
<string name='lightAnimation.colorRed.target'>color red</string>
Set which value to use of <parameter>.target
.
lightAnimation.<parameter>.parameter
or lightAnimation({id}).<parameter>.parameter
Allowed Values:
Value | Description |
---|---|
positionX | Bone local position X coordinate. |
positionY | Bone local position Y coordinate. |
positionZ | Bone local position Z coordinate. |
rotationX | Bone local rotation X coordinate in degrees. |
rotationY | Bone local rotation Y coordinate in degrees. |
rotationZ | Bone local rotation Z coordinate in degrees. |
scaleX | Bone local scale X coordinate. |
scaleY | Bone local scale Y coordinate. |
scaleZ | Bone local scale Z coordinate. |
weight | Vertex position set weight. |
positionZ
<string name='lightAnimation.colorRed.parameter'>positionZ</string>
Set lower remap value. Input values obtained from target is remapped before applying to the light parameter. This linearly maps the lower remap value (default 0) to 0 output value and the upper remap value (default 1) to 1 output value. Values outside the remap range are extrapolated.
lightAnimation.<parameter>.remapLower
or lightAnimation({id}).<parameter>.remapLower
0
<float name='lightAnimation.colorRed.remapLower'>0.5</float>
Set upper remap value. Input values obtained from target is remapped before applying to the light parameter. This linearly maps the lower remap value (default 0) to 0 output value and the upper remap value (default 1) to 1 output value. Values outside the remap range are extrapolated.
lightAnimation.<parameter>.remapUpper
or lightAnimation({id}).<parameter>.remapUpper
1
<float name='lightAnimation.colorRed.remapUpper'>1.5</float>
This behavior provides no events:
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace lightAnimation
with lightAnimation(id)
.
Set one or more light parameters.
Parameter | Value | Description |
---|---|---|
enabled | true , false | Set if animation is enabled |
time | float | Set animation time in seconds |
time.relative | float | Set animation time in percentage from 0 (begin) to 1 (end) |
This is an example of using this action:
<action name='lightAnimation.set'> <parameter name='enabled'>true</parameter> </action>
Check one or more light parameters. Action succeeds if all parameter value matches their respective light parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a light parameter matches (or not).
Parameter | Value | Description |
---|---|---|
enabled | true , false | Animation is enabled |
time.less | float | Animation time is less than value in seconds |
time.greater | float | Animation time is greater than value in seconds |
time.relative.less | float | Relative animation time (0=begin, 1=end) is less than value in seconds |
time.relative.greater | float | Relative animation time (0=begin, 1=end) is greater than value in seconds |
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='lightAnimation.check'> <parameter name='enabled'>true</parameter> <parameter name='time.less'>3</parameter> </action> <!-- actions here run only if animation is enabled and playback time is less than 3 seconds --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace lightAnimation
with lightAnimation(id)
.
Check one or more light parameters. Conditions returns true if all parameter value match their respective light parameter. This condition is typically used to run an action or sequence of actions as long as light conditions are true.
Parameter | Value | Description |
---|---|---|
lightAnimation.enabled | true , false | Animation is enabled |
lightAnimation.time.less | float | Animation time is less than value in seconds |
lightAnimation.time.greater | float | Animation time is greater than value in seconds |
lightAnimation.time.relative.less | float | Relative animation time (0=begin, 1=end) is less than value in seconds |
lightAnimation.time.relative.greater | float | Relative animation time (0=begin, 1=end) is greater than value in seconds |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='lightAnimation.enabled'>true</parameter> <parameter name='lightAnimation.time.less'>3</parameter> <condition>lightAnimation.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends no state machine events.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.28
This example defines an element which contains a light which is animated.
class MyElement extends BehaviorElementClass public var ECBehaviorLight light public var ECBehaviorLightAnimation lightAnimation func new() light = ECBehaviorLight.new(this, null) light.getLight().getColor().setColor(Color.white) light.getLight().getIntensity().setValue(10) lightAnimation = ECBehaviorLightAnimation.new(this, light) lightAnimation.getAnimation().setPath("/content/light/bulb.deanim") lightAnimation.getMove().setValue("flicker") lightAnimation.getLightParameter(ECBehaviorLightAnimation.LightParameter.intensity).getTarget().setValue("light.intensity") 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='ECBehaviorLight'> <color name='.color' r='1' g='1' b='1'/> <float name='.intensity'>10</float> </behavior> <behavior type='ECBehaviorLightAnimation'> <!-- optional: use BaseGameApp trigger table. game can add more supported values. default value is 'default' --> <string name='triggerTable'>default</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: use behavior tree with id instead of empty string --> <string name='behaviorTree'>second</string> <!-- optional: use state machine with id instead of empty string --> <string name='stateMachine'>second</string> <!-- optional: light behavior to use instead of default one --> <string name='light'>other</string> <!-- optional: component behavior to use instead of default one if present --> <string name='component'>second</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.animation'>/content/light/bulb.deanim</string> <string name='.move'>flicker</string> <string name='.intensity.target'>intensity</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorLightAnimation' id='second'/> </elementClass>