User Tools

Site Tools


dragengine:modules:dragonscript:behavior_playerinputlook

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.

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'>
    <!-- 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.txt · Last modified: 2025/03/13 11:39 by dragonlord