38 lines
827 B
GDScript
38 lines
827 B
GDScript
extends Node
|
|
|
|
|
|
export(float) var inner_deadzone = 0.2
|
|
export(float) var outer_deadzone = 0.8
|
|
|
|
|
|
func _process(delta):
|
|
var input = Vector2(Input.get_joy_axis(0, 0), Input.get_joy_axis(0, 1))
|
|
|
|
# Remove signs to reduce the number of cases
|
|
var signs = Vector2(sign(input.x), sign(input.y))
|
|
input = Vector2(abs(input.x), abs(input.y))
|
|
|
|
# Deazones for each axis
|
|
if input.x > outer_deadzone:
|
|
input.x = 1.0
|
|
elif input.x < inner_deadzone:
|
|
input.x = 0.0
|
|
else:
|
|
input.x = inverse_lerp(inner_deadzone, outer_deadzone, input.x)
|
|
|
|
if input.y > outer_deadzone:
|
|
input.y = 1.0
|
|
elif input.y < inner_deadzone:
|
|
input.y = 0.0
|
|
else:
|
|
input.y = inverse_lerp(inner_deadzone, outer_deadzone, input.y)
|
|
|
|
# Re-apply signs
|
|
input *= signs
|
|
|
|
# Limit at length 1
|
|
if input.length() > 1.0:
|
|
input /= input.length()
|
|
|
|
print(input)
|