User Tools

Site Tools


dragengine:modules:dragonscript:behavior_playerinputlook

This is an old revision of the document!


ECBehaviorPlayerInputLook

Behavior element behavior adding looking around player input.

Keeps track of looking around player input and applies them to actor locomotion.

Digital Input

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.

Analog Input

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.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix playerInputLook. .

speedLookHorizontal

Set look left right speed in degrees per second.

  • Full name: playerInputLook.speedLookHorizontal
  • Type: float
  • Default Value: 45
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='playerInputLook.speedLookHorizontal'>30</float>

speedLookVertical

Set look up down speed in degrees per second.

  • Full name: playerInputLook.speedLookVertical
  • Type: float
  • Default Value: 45
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='playerInputLook.speedLookVertical'>30</float>

analogFactorLookHorizontal

Set analog Look left right factor relative to left right input speed.

  • Full name: playerInputLook.analogFactorLookHorizontal
  • Type: float
  • Default Value: 0.01
  • Example (*.deeclass)
    <float name='playerInputLook.analogFactorLookHorizontal'>0.02</float>

analogFactorLookVertical

Set analog Look up down factor relative to up down input speed.

  • Full name: playerInputLook.analogFactorLookVertical
  • Type: float
  • Default Value: 0.01
  • Example (*.deeclass)
    <float name='playerInputLook.analogFactorLookVertical'>0.02</float>

Events

This behavior has no events.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present.

playerInputLook.set

Set one or more player input look parameters.

ParameterValueDescription
reset Reset player input look
lefttrue, falseLook left key pressed
left.toggle Toggle look left key pressed
righttrue, falseLook right key pressed
right.toggle Toggle look right key pressed
uptrue, falseLook up key pressed
up.toggle Toggle look up key pressed
downtrue, falseLook down key pressed
down.toggle Toggle look down key pressed
speed.horizontalfloatHorizontal looking speed in m/s
analog.horizontalfloatAnalog horizontal looking in the range from -180 to 180 degrees
analog.horizontal.factorfloatAnalog horizontal looking multiplicator
analog.horizontal.stickyfloatSticky analog horizontal looking in the range from -180 to 180 degrees
speed.verticalfloatVertical looking speed in m/s
analog.verticalfloatAnalog vertical looking in the range from -180 to 180 degrees
analog.vertical.factorfloatAnalog vertical looking multiplicator
analog.vertical.stickyfloatSticky 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>

playerInputLook.check

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).

ParameterValueDescription
lefttrue, falseLook left key pressed
righttrue, falseLook right key pressed
uptrue, falseLook up key pressed
downtrue, falseLook down key pressed
speed.horizontal.lessfloatHorizontal speed is less than float value m/s
speed.horizontal.greaterfloatHorizontal speed is greater than float value m/s
analog.horizontal.lessfloatAnalog horizontal value is less than value
analog.horizontal.greaterfloatAnalog horizontal value is greater than value
analog.horizontal.sticky.lessfloatSticky analog horizontal value is less than value
analog.horizontal.sticky.greaterfloatSticky analog horizontal value is greater than value
speed.vertical.lessfloatVertical speed is less than float value m/s
speed.vertical.greaterfloatVertical speed is greater than float value m/s
analog.vertical.lessfloatAnalog vertical value is less than value
analog.vertical.greaterfloatAnalog vertical value is greater than value
analog.vertical.sticky.lessfloatSticky analog vertical value is less than value
analog.vertical.sticky.greaterfloatSticky 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>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present.

playerInputLook.check

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.

ParameterValueDescription
playerInputLook.lefttrue, falseLook left key pressed
playerInputLook.righttrue, falseLook right key pressed
playerInputLook.uptrue, falseLook up key pressed
playerInputLook.downtrue, falseLook down key pressed
playerInputLook.speed.horizontal.lessfloatHorizontal speed is less than float value m/s
playerInputLook.speed.horizontal.greaterfloatHorizontal speed is greater than float value m/s
playerInputLook.analog.horizontal.lessfloatAnalog horizontal value is less than value
playerInputLook.analog.horizontal.greaterfloatAnalog horizontal value is greater than value
playerInputLook.analog.horizontal.sticky.lessfloatSticky analog horizontal value is less than value
playerInputLook.analog.horizontal.sticky.greaterfloatSticky analog horizontal value is greater than value
playerInputLook.speed.vertical.lessfloatVertical speed is less than float value m/s
playerInputLook.speed.vertical.greaterfloatVertical speed is greater than float value m/s
playerInputLook.analog.vertical.lessfloatAnalog vertical value is less than value
playerInputLook.analog.vertical.greaterfloatAnalog vertical value is greater than value
playerInputLook.analog.vertical.sticky.lessfloatSticky analog vertical value is less than value
playerInputLook.analog.vertical.sticky.greaterfloatSticky 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>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior send no events to state machine.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does not required element class to be persistable (setPersistable).

API Documentation

ECBehaviorPlayerInputLook.

Since DragonScript Module Version 1.0

Use Cases

  • Track looking around player input and apply it to locomotion.

Element Class Example

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

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='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>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_playerinputlook.1746631791.txt.gz · Last modified: 2025/05/07 15:29 by dragonlord