Advertisement
Guest User

Character.gd

a guest
Oct 12th, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends KinematicBody2D
  2.  
  3. var velocity = Vector2.ZERO
  4.  
  5. var run_speed = 350
  6. var jump_speed = -1000
  7. var gravity = 2500
  8.  
  9. var jump_possible = true
  10.  
  11.  
  12. func get_input():
  13.     velocity.x = 0
  14.     var right = Input.is_action_pressed("ui_right")
  15.     var left = Input.is_action_pressed("ui_left")
  16.     var jump = Input.is_action_just_pressed("ui_select")
  17.    
  18.     if right:
  19.         velocity.x += run_speed
  20.     if left:
  21.         velocity.x -= run_speed
  22.     if jump_possible and jump:
  23.         velocity.y = jump_speed
  24.  
  25.  
  26. func _physics_process(delta):
  27.     if is_on_floor():
  28.         $JumpPossibleTimer.start()
  29.         jump_possible = true
  30.     else:
  31.         velocity.y += gravity * delta
  32.     get_input()
  33.     move_and_slide(velocity, Vector2(0, -1))
  34.  
  35.  
  36. func _on_JumpPossibleTimer_timeout():
  37.     jump_possible = false
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement