Advertisement
gdquest

Platform #3 - Player jump mechanic

Jan 31st, 2017
5,733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var input_direction = 0
  4. var direction = 0
  5.  
  6. var speed_x = 0
  7. var velocity = Vector2()
  8.  
  9. const MAX_SPEED = 600
  10. const ACCELERATION = 1000
  11. const DECELERATION = 2000
  12.  
  13.  
  14. func _ready():
  15. set_process(true)
  16. set_process_input(true)
  17.  
  18.  
  19. func _input(event):
  20. pass
  21.  
  22.  
  23. func _process(delta):
  24. # INPUT
  25. if input_direction:
  26. direction = input_direction
  27.  
  28. if Input.is_action_pressed("move_left"):
  29. input_direction = -1
  30. elif Input.is_action_pressed("move_right"):
  31. input_direction = 1
  32. else:
  33. input_direction = 0
  34.  
  35. # MOVEMENT
  36. if input_direction == - direction:
  37. speed_x /= 3
  38. if input_direction:
  39. speed_x += ACCELERATION * delta
  40. else:
  41. speed_x -= DECELERATION * delta
  42. speed_x = clamp(speed_x, 0, MAX_SPEED)
  43.  
  44. velocity.x = speed_x * delta * direction
  45. move(velocity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement