Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. const TOP = Vector2(0,-1)
  4. const LEFT = Vector2(-1,0)
  5. const RIGHT = Vector2(1,0)
  6. const DOWN = Vector2(0,1)
  7. const NONE = Vector2(0,0)
  8.  
  9. var motion = NONE
  10. func _ready():
  11. pass
  12.  
  13.  
  14. func _physics_process(delta):
  15.  
  16. if Input.is_action_just_released('move_up'):
  17. if motion == TOP:
  18. motion = NONE
  19. if Input.is_action_just_released('move_left'):
  20. if motion == LEFT:
  21. motion = NONE
  22. if Input.is_action_just_released('move_right'):
  23. if motion == RIGHT:
  24. motion = NONE
  25. if Input.is_action_just_released('move_down'):
  26. if motion == DOWN:
  27. motion = NONE
  28.  
  29.  
  30.  
  31. if Input.is_action_just_pressed('move_up'):
  32. motion = TOP
  33. if Input.is_action_just_pressed('move_left'):
  34. motion = LEFT
  35. if Input.is_action_just_pressed('move_right'):
  36. motion = RIGHT
  37. if Input.is_action_just_pressed('move_down'):
  38. motion = DOWN
  39. move_and_slide(motion*40)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement