Player.gd 461 B

123456789101112131415161718192021222324
  1. extends CharacterBody2D
  2. const SPEED = 300.0
  3. func _physics_process(delta):
  4. if Input.is_action_pressed("ui_right"):
  5. velocity.x = SPEED
  6. elif Input.is_action_pressed("ui_left"):
  7. velocity.x = -SPEED
  8. else:
  9. velocity.x = move_toward(velocity.x, 0, SPEED)
  10. if Input.is_action_pressed("ui_down"):
  11. velocity.y = SPEED
  12. elif Input.is_action_pressed("ui_up"):
  13. velocity.y = -SPEED
  14. else:
  15. velocity.y = move_toward(velocity.y, 0, SPEED)
  16. move_and_slide()