Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Mintteacup |
When I spam the jump key my character sometimes (I might just not be consistent in hitting the jump button) jumps higher than usual and I have no idea why.
Here is a video showing this: Video
extends KinematicBody2D
var velocity = Vector2(0,0)
var bufferedJump = false
var coyoteJump = false
onready var jumpBufferTimer = $jumpBufferTimer
onready var coyoteTimer = $coyoteTimer
const SPEED = 500
const GRAVITY = 45
const JUMPFORCE = -1000
func _physics_process(delta):
if Input.is_action_pressed("right"):
velocity.x = SPEED
$Sprite.play("walk")
$Sprite.flip_h = false
elif Input.is_action_pressed("left"):
velocity.x = -SPEED
$Sprite.play("walk")
$Sprite.flip_h = true
else:
$Sprite.play("idle")
if not is_on_floor():
$Sprite.play("air")
velocity.y += GRAVITY
if is_on_floor() or !coyoteTimer.is_stopped():
if Input.is_action_just_pressed("jump") or bufferedJump:
velocity.y = JUMPFORCE
bufferedJump = false
else:
if Input.is_action_just_pressed("jump"):
bufferedJump = true
jumpBufferTimer.start()
var was_on_floor = is_on_floor()
velocity = move_and_slide(velocity, Vector2.UP)
if was_on_floor and not is_on_floor():
coyoteTimer.start()
velocity.x = lerp(velocity.x, 0, 0.2)
func _on_jumpBufferTimer_timeout():
bufferedJump = false