coyote: rajout du coyote time pout le saut

le joueur peut sauter pendant quelques frames après avoir quitté le sol.
ça rend le jeu beaucoup plus smooth
This commit is contained in:
Thomas Lavocat
2023-04-29 17:06:08 +02:00
parent 8016844ffe
commit c23d9d3914

View File

@@ -28,7 +28,7 @@ var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
# Nombre de frames coyote durant lesquelle le joueur peut encore sauter
# sans encore être au sol
@export var COYOTE_LENGTH := 20
@export var COYOTE_LENGTH := 15
# Direction dans laquelle est positioné le personnage.
var direction : int = 1
@@ -47,6 +47,7 @@ var jumping : bool = false
var need_jump : bool = false
var jumping_step : int = -1
var jump_key_counter : int = 0
var coyote_ground = []
var falling_step : int = -1
@@ -168,14 +169,19 @@ func end_jump():
jump_key_counter = 0
func _physics_process(delta: float) -> void:
coyote_ground.append(is_on_floor())
if coyote_ground.size() > COYOTE_LENGTH:
coyote_ground.remove_at(0)
pressing_wall = wall_detect_left.is_colliding() or wall_detect_right.is_colliding()
grab_wall = pressing_wall and Input.is_action_pressed("grab" + action_suffix)
if Input.is_action_just_pressed("jump" + action_suffix):
if ground_far_detect.is_colliding() or is_on_floor():
if ground_far_detect.is_colliding() or (is_on_floor() or coyote_ground[0]):
need_jump=true
if need_jump and is_on_floor():
if need_jump and (is_on_floor() or coyote_ground[0]):
need_jump = false
if not jumping:
jumping = true