phs-galaxy/InputConverter.gd
karl 219c8731f5 Add shooting enemy which shoots at future player pos
Works fairly well, although it doesn't account for changing acceleration which happens due to the changing gravity. I guess this is good enough, since it does hit if the player isn't careful
2021-06-07 16:41:56 +02:00

36 lines
811 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()