Skip to content

Instantly share code, notes, and snippets.

@aindong
Created February 6, 2022 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aindong/dd0cd9fdd3336226a2b8c9dff55cae39 to your computer and use it in GitHub Desktop.
Save aindong/dd0cd9fdd3336226a2b8c9dff55cae39 to your computer and use it in GitHub Desktop.
Move a sprite base on input
func _process(delta):
var direction = Vector2.ZERO
if Input.is_action_pressed("move_right"):
direction.x += 1
if Input.is_action_pressed("move_left"):
direction.x -= 1
if Input.is_action_pressed("move_down"):
direction.y += 1
if Input.is_action_pressed("move_up"):
direction.y -= 1
if direction.length() > 1:
direction = direction.normalized()
position += direction * speed * delta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment