Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var velocity = Vector2.ZERO
- var run_speed = 350
- var jump_speed = -1000
- var gravity = 2500
- var jump_possible = true
- func get_input():
- velocity.x = 0
- var right = Input.is_action_pressed("ui_right")
- var left = Input.is_action_pressed("ui_left")
- var jump = Input.is_action_just_pressed("ui_select")
- if right:
- velocity.x += run_speed
- if left:
- velocity.x -= run_speed
- if jump_possible and jump:
- velocity.y = jump_speed
- func _physics_process(delta):
- if is_on_floor():
- $JumpPossibleTimer.start()
- jump_possible = true
- else:
- velocity.y += gravity * delta
- get_input()
- move_and_slide(velocity, Vector2(0, -1))
- func _on_JumpPossibleTimer_timeout():
- jump_possible = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement