In max_jumps I set the maximum number of jumps. But in the end he jumps 3 times, that is, he will always jump 1 time more than specified in max_jumps. Wtf?
Print output if I pressed UP button 3 times:
1
1
2
Player script:
extends KinematicBody2D
var motion = Vector2()
var player = {
"speed": 20000,
"gravity": 2500,
"jump": -40000,
"count_jumps": 0,
"max_jumps": 2
}
func _physics_process(delta):
# movement
if Input.is_action_pressed("ui_left"):
motion.x = -player.speed * delta
elif Input.is_action_pressed("ui_right"):
motion.x = player.speed * delta
else:
motion.x = 0
# jump
if Input.is_action_just_pressed("ui_up") && player.count_jumps < player.max_jumps:
player.count_jumps += 1
motion.y = player.jump * delta
print(player.count_jumps)
if is_on_floor():
player.count_jumps = 0
#gravity
motion.y += player.gravity * delta
motion = move_and_slide(motion, Vector2.UP)