troll.gd 560 B

12345678910111213141516171819202122232425
  1. extends KinematicBody2D
  2. # This is a demo showing how KinematicBody2D
  3. # move_and_slide works.
  4. # Member variables
  5. const MOTION_SPEED = 160 # Pixels/second
  6. func _physics_process(delta):
  7. var motion = Vector2()
  8. if Input.is_action_pressed("move_up"):
  9. motion += Vector2(0, -1)
  10. if Input.is_action_pressed("move_bottom"):
  11. motion += Vector2(0, 1)
  12. if Input.is_action_pressed("move_left"):
  13. motion += Vector2(-1, 0)
  14. if Input.is_action_pressed("move_right"):
  15. motion += Vector2(1, 0)
  16. motion = motion.normalized() * MOTION_SPEED
  17. move_and_slide(motion)