diff --git a/princesse.gd b/princesse.gd index 19a96f9..826dfa9 100644 --- a/princesse.gd +++ b/princesse.gd @@ -7,6 +7,7 @@ extends CharacterBody2D var gravity: int = ProjectSettings.get("physics/2d/default_gravity") @onready var wall_detect_left := $wall_detect_left as RayCast2D @onready var wall_detect_right := $wall_detect_right as RayCast2D +@onready var ground_far_detect := $ground_far_detect as RayCast2D @onready var animation := $AnimatedSprite2D as AnimatedSprite2D @onready var camera := $Camera2D as Camera2D @@ -43,6 +44,7 @@ var init_direction_change = true # variables d'état relatives au saut var jumping : bool = false +var need_jump : bool = false var jumping_step : int = -1 var jump_key_counter : int = 0 @@ -170,11 +172,15 @@ func _physics_process(delta: float) -> void: grab_wall = pressing_wall and Input.is_action_pressed("grab" + action_suffix) if Input.is_action_just_pressed("jump" + action_suffix): - if is_on_floor(): - if not jumping: - jumping = true - jumping_step = JUMP_SPEED_TABLE.size()-1 - jump_key_counter = 0 + if ground_far_detect.is_colliding() or is_on_floor(): + need_jump=true + + if need_jump and is_on_floor(): + need_jump = false + if not jumping: + jumping = true + jumping_step = JUMP_SPEED_TABLE.size()-1 + jump_key_counter = 0 if Input.is_action_pressed("jump" + action_suffix): if jumping: diff --git a/princesse.tscn b/princesse.tscn index 7cce985..746270d 100644 --- a/princesse.tscn +++ b/princesse.tscn @@ -215,6 +215,10 @@ animation = &"idle" target_position = Vector2(-10, 0) collision_mask = 16 +[node name="wall_detect_right" type="RayCast2D" parent="."] +target_position = Vector2(14, 0) +collision_mask = 16 + [node name="Camera2D" type="Camera2D" parent="."] zoom = Vector2(2, 2) @@ -222,6 +226,6 @@ zoom = Vector2(2, 2) position = Vector2(2, 0) shape = SubResource("CapsuleShape2D_6r7th") -[node name="wall_detect_right" type="RayCast2D" parent="."] -target_position = Vector2(14, 0) +[node name="ground_far_detect" type="RayCast2D" parent="."] +target_position = Vector2(0, 38) collision_mask = 16