Skip to content

Instantly share code, notes, and snippets.

@pegasusearl
Last active December 17, 2019 03:06
Show Gist options
  • Select an option

  • Save pegasusearl/15e32bcdba4efd5a8b2da4a66963709f to your computer and use it in GitHub Desktop.

Select an option

Save pegasusearl/15e32bcdba4efd5a8b2da4a66963709f to your computer and use it in GitHub Desktop.
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