Last active
December 17, 2019 03:06
-
-
Save pegasusearl/15e32bcdba4efd5a8b2da4a66963709f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| extends KinematicBody2D | |
| class_name TopDown4Direction | |
| var movement_speed:float = 300 # in pixels per second. | |
| func _physics_process(delta): | |
| var movement:Vector2 | |
| if Input.is_action_pressed("ui_up"): # I used "ui_up" since it's already available. Better use something else. | |
| movement = Vector2.UP # Vector2.UP is Vector2(0,-1) | |
| elif Input.is_action_pressed("ui_down"): | |
| movement = Vector2.DOWN | |
| elif Input.is_action_pressed("ui_left"): | |
| movement = Vector2.LEFT | |
| elif Input.is_action_pressed("ui_right"): | |
| movement = Vector2.RIGHT | |
| move_and_slide(movement * movement_speed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment