Created
February 6, 2022 02:54
-
-
Save aindong/dd0cd9fdd3336226a2b8c9dff55cae39 to your computer and use it in GitHub Desktop.
Move a sprite base on input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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