Skip to content

Instantly share code, notes, and snippets.

@regakakobigman
Last active May 9, 2020 03:23
Show Gist options
  • Save regakakobigman/9b9b44d50fd4012036e4f2681f3b5f7f to your computer and use it in GitHub Desktop.
Save regakakobigman/9b9b44d50fd4012036e4f2681f3b5f7f to your computer and use it in GitHub Desktop.
Only take the most recent axis input
var moving := Vector2()
func _physics_process(delta: float) -> void:
# Input singleton should only be used from _physics_process
update_moving()
func update_moving() -> void:
# This makes moving a little more intuitive with the arrow keys
# Shouldn't be needed for unmodified d-pads, but should be used just in case
# Not needed for analog sticks; just get input strength
var move_left = Input.is_action_pressed("move_left")
var move_right = Input.is_action_pressed("move_right")
var move_up = Input.is_action_pressed("move_up")
var move_down = Input.is_action_pressed("move_down")
if not (move_left or move_right):
moving.x = 0
elif move_left and Input.is_action_just_released("move_right"):
moving.x = -1
elif move_right and Input.is_action_just_released("move_left"):
moving.x = 1
elif Input.is_action_just_pressed("move_left"):
moving.x = -1
elif Input.is_action_just_pressed("move_right"):
moving.x = 1
if not (move_up or move_down):
moving.y = 0
elif move_down and Input.is_action_just_released("move_up"):
moving.y = -1
elif move_up and Input.is_action_just_released("move_down"):
moving.y = 1
elif Input.is_action_just_pressed("move_down"):
moving.y = -1
elif Input.is_action_just_pressed("move_up"):
moving.y = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment