This is an old revision of the document!
Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorPlayerInputLook
Behavior element behavior adding looking around player input.
Keeps track of looking around player input and applies them to actor locomotion.
Supports digital input by player for looking left-right and up-down using digital input devices like keyboard or game pad buttons. The setSpeedLookHorizontal() and setSpeedLookVertical() methods set the speed of looking while the input is enabled. The calculation of looking delta by digital input is this:
delta = (+/-) speed * elapsedTime
.
Here +
is if left input is enabled while -
is used if right input is enabled. Using negative speed switches direction.
Supports analog input by player for looking left-right and up-down using analog input devices like mouse, game pad analog sticksothers. The analog input can be set directly from the input event (for example mouse move deltas). The setAnalogFactorLookHorizontal() and setAnalogFactorLookVertical() methods set the sensitivity of the input value transforming it into a value comparable to using digital input. The default value is 0.01
resulting in analog input suitable for first person navigation. Smaller values make analog input slower increasing accuracy pointing at specific locations while larger values make analog input faster. The same holds true for changing the digital input speed. The calculation of looking delta by analog input is this:
delta = analogInput * analogFactor * speed
.
This calculation applies only to non-sticky input as this originates from mouse input devices only. Sticky inputs originating from game pads and similar used the elapsed time instead of analogFactor and thus are similar to digital input. Using negative factor switches direction. Using negative factor and speed keeps the direction unchanged.
This behavior can be used only once on an element.
Element class properties have the prefix playerInputLook.
.
Set look left right speed in degrees per second.
playerInputLook.speedLookHorizontal
<float name='playerInputLook.speedLookHorizontal'>30</float>
Set look up down speed in degrees per second.
playerInputLook.speedLookVertical
<float name='playerInputLook.speedLookVertical'>30</float>
Set analog Look left right factor relative to left right input speed.
playerInputLook.analogFactorLookHorizontal
<float name='playerInputLook.analogFactorLookHorizontal'>0.02</float>
Set analog Look up down factor relative to up down input speed.
playerInputLook.analogFactorLookVertical
<float name='playerInputLook.analogFactorLookVertical'>0.02</float>
This behavior has no events.
This behavior adds these behavior tree actions if behavior tree is present.
Set one or more player input look parameters.
Parameter | Value | Description |
---|---|---|
reset | Reset player input look | |
left | true , false | Look left key pressed |
left.toggle | Toggle look left key pressed | |
right | true , false | Look right key pressed |
right.toggle | Toggle look right key pressed | |
up | true , false | Look up key pressed |
up.toggle | Toggle look up key pressed | |
down | true , false | Look down key pressed |
down.toggle | Toggle look down key pressed | |
speed.horizontal | float | Horizontal looking speed in m/s |
analog.horizontal | float | Analog horizontal looking in the range from -180 to 180 degrees |
analog.horizontal.factor | float | Analog horizontal looking multiplicator |
analog.horizontal.sticky | float | Sticky analog horizontal looking in the range from -180 to 180 degrees |
speed.vertical | float | Vertical looking speed in m/s |
analog.vertical | float | Analog vertical looking in the range from -180 to 180 degrees |
analog.vertical.factor | float | Analog vertical looking multiplicator |
analog.vertical.sticky | float | Sticky analog vertical looking in the range from -180 to 180 degrees |
This is an example of using this action:
<action name='playerInputLook.set'> <parameter name='left'>true</parameter> </action>
Check one or more player input look parameters. Action succeeds if all parameter value matches their respective player input look parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a player input look parameter matches (or not).
Parameter | Value | Description |
---|---|---|
left | true , false | Look left key pressed |
right | true , false | Look right key pressed |
up | true , false | Look up key pressed |
down | true , false | Look down key pressed |
speed.horizontal.less | float | Horizontal speed is less than float value m/s |
speed.horizontal.greater | float | Horizontal speed is greater than float value m/s |
analog.horizontal.less | float | Analog horizontal value is less than value |
analog.horizontal.greater | float | Analog horizontal value is greater than value |
analog.horizontal.sticky.less | float | Sticky analog horizontal value is less than value |
analog.horizontal.sticky.greater | float | Sticky analog horizontal value is greater than value |
speed.vertical.less | float | Vertical speed is less than float value m/s |
speed.vertical.greater | float | Vertical speed is greater than float value m/s |
analog.vertical.less | float | Analog vertical value is less than value |
analog.vertical.greater | float | Analog vertical value is greater than value |
analog.vertical.sticky.less | float | Sticky analog vertical value is less than value |
analog.vertical.sticky.greater | float | Sticky analog vertical value is greater than value |
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='playerInputLook.check'> <parameter name='left'>true</parameter> </action> <!-- actions here run only if look left key is pressed --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present.
Check one or more player input look parameters. Conditions returns true if all parameter value match their respective player input look parameter. This condition is typically used to run an action or sequence of actions as long as player input look conditions are true.
Parameter | Value | Description |
---|---|---|
playerInputLook.left | true , false | Look left key pressed |
playerInputLook.right | true , false | Look right key pressed |
playerInputLook.up | true , false | Look up key pressed |
playerInputLook.down | true , false | Look down key pressed |
playerInputLook.speed.horizontal.less | float | Horizontal speed is less than float value m/s |
playerInputLook.speed.horizontal.greater | float | Horizontal speed is greater than float value m/s |
playerInputLook.analog.horizontal.less | float | Analog horizontal value is less than value |
playerInputLook.analog.horizontal.greater | float | Analog horizontal value is greater than value |
playerInputLook.analog.horizontal.sticky.less | float | Sticky analog horizontal value is less than value |
playerInputLook.analog.horizontal.sticky.greater | float | Sticky analog horizontal value is greater than value |
playerInputLook.speed.vertical.less | float | Vertical speed is less than float value m/s |
playerInputLook.speed.vertical.greater | float | Vertical speed is greater than float value m/s |
playerInputLook.analog.vertical.less | float | Analog vertical value is less than value |
playerInputLook.analog.vertical.greater | float | Analog vertical value is greater than value |
playerInputLook.analog.vertical.sticky.less | float | Sticky analog vertical value is less than value |
playerInputLook.analog.vertical.sticky.greater | float | Sticky analog vertical value is greater than value |
playerInputLook.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 condition:
<action name='myAction' id='doing something'> <parameter name='playerInputLook.left'>true</parameter> <condition>playerInputLook.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior send no events to state machine.
This behavior requires no other behaviors.
This behavior does not required element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which tracks player looking around input.
class MyElement extends BehaviorElementClass public var ECBehaviorPlayerInputLook playerInputLook func new() ECBehaviorPlayerInputLook.new(this) 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='ECBehaviorPlayerInputLook'> <!-- 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> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.speedLookHorizontal'>30</string> </behavior> </elementClass>