feat: adds a cd to the jump to prevent spam jumping up a slope

This commit is contained in:
DottsGit
2026-06-05 00:54:19 -04:00
parent 9f3264170e
commit 2c35f5074a
7 changed files with 23 additions and 7 deletions
+3
View File
@@ -49,6 +49,9 @@ class_name MovementParams
@export var wall_ray_up_height: float = 0.6 @export var wall_ray_up_height: float = 0.6
@export var wall_ray_down_height: float = -0.3 @export var wall_ray_down_height: float = -0.3
# ── Jumping ───────────────────────────────────────────────────────────────────
@export var jump_cooldown: float = 0.27
# ── Wall Cling ──────────────────────────────────────────────────────────────── # ── Wall Cling ────────────────────────────────────────────────────────────────
@export var wall_cling_slide_speed: float = -1.5 @export var wall_cling_slide_speed: float = -1.5
@export var wall_cling_stamina_drain: float = 2.0 @export var wall_cling_stamina_drain: float = 2.0
+5
View File
@@ -28,6 +28,7 @@ var on_ground: bool = false
var last_ground_time: float = 0.0 var last_ground_time: float = 0.0
var jump_buffer_time: float = 0.0 var jump_buffer_time: float = 0.0
var coyote_timer: float = 0.0 var coyote_timer: float = 0.0
var jump_cooldown_timer: float = 0.0
var current_jump_count: int = 0 var current_jump_count: int = 0
var chain_timer: float = 0.0 var chain_timer: float = 0.0
var chain_count: int = 0 var chain_count: int = 0
@@ -59,6 +60,10 @@ func _physics_process(delta: float) -> void:
jump_buffer_time = params.jump_buffer jump_buffer_time = params.jump_buffer
else: else:
jump_buffer_time = maxf(jump_buffer_time - delta, 0.0) jump_buffer_time = maxf(jump_buffer_time - delta, 0.0)
# Update jump cooldown
if jump_cooldown_timer > 0.0:
jump_cooldown_timer = maxf(jump_cooldown_timer - delta, 0.0)
# Update chain timer # Update chain timer
if chain_timer > 0.0 and on_ground: if chain_timer > 0.0 and on_ground:
+4 -2
View File
@@ -65,7 +65,7 @@ func update(delta: float) -> void:
machine.current_jump_count = 0 machine.current_jump_count = 0
# Bunny hop: if jump was buffered or pressed on landing frame # Bunny hop: if jump was buffered or pressed on landing frame
if machine.input_jump_pressed or machine.jump_buffer_time > 0.0: if (machine.input_jump_pressed or machine.jump_buffer_time > 0.0) and machine.jump_cooldown_timer <= 0.0:
var land_speed := Vector3(player.velocity.x, 0.0, player.velocity.z).length() var land_speed := Vector3(player.velocity.x, 0.0, player.velocity.z).length()
var bhop_speed := maxf(land_speed, minf(land_speed + params.bunny_hop_speed_gain, params.bunny_hop_speed_cap)) var bhop_speed := maxf(land_speed, minf(land_speed + params.bunny_hop_speed_gain, params.bunny_hop_speed_cap))
# Maintain horizontal direction, boost speed # Maintain horizontal direction, boost speed
@@ -81,6 +81,7 @@ func update(delta: float) -> void:
machine.on_ground = false machine.on_ground = false
machine.jump_buffer_time = 0.0 machine.jump_buffer_time = 0.0
machine.register_chain_mechanic("bunny_hop") machine.register_chain_mechanic("bunny_hop")
machine.jump_cooldown_timer = params.jump_cooldown
if player.jump_player: if player.jump_player:
player.jump_player.play() player.jump_player.play()
# Stay in air state # Stay in air state
@@ -90,8 +91,9 @@ func update(delta: float) -> void:
return return
# ── Double Jump ─────────────────────────────────────────────────────── # ── Double Jump ───────────────────────────────────────────────────────
if machine.input_jump_just_pressed and machine.current_jump_count < params.double_jump_max_count: if machine.input_jump_just_pressed and machine.current_jump_count < params.double_jump_max_count and machine.jump_cooldown_timer <= 0.0:
player.velocity.y = params.double_jump_velocity player.velocity.y = params.double_jump_velocity
machine.jump_cooldown_timer = params.jump_cooldown
machine.current_jump_count += 1 machine.current_jump_count += 1
machine.register_chain_mechanic("double_jump") machine.register_chain_mechanic("double_jump")
if player.double_jump_player: if player.double_jump_player:
+4 -2
View File
@@ -28,24 +28,26 @@ func update(delta: float) -> void:
var vel: Vector3 = player.velocity var vel: Vector3 = player.velocity
# ── Jump (coyote time + jump buffer) ────────────────────────────────── # ── Jump (coyote time + jump buffer) ──────────────────────────────────
if machine.input_jump_just_pressed and machine.coyote_timer > 0.0: if machine.input_jump_just_pressed and machine.coyote_timer > 0.0 and machine.jump_cooldown_timer <= 0.0:
player.velocity.y = params.jump_velocity player.velocity.y = params.jump_velocity
machine.current_jump_count = 1 machine.current_jump_count = 1
machine.on_ground = false machine.on_ground = false
machine.coyote_timer = 0.0 machine.coyote_timer = 0.0
machine.register_chain_mechanic("jump") machine.register_chain_mechanic("jump")
machine.jump_cooldown_timer = params.jump_cooldown
if player.jump_player: if player.jump_player:
player.jump_player.play() player.jump_player.play()
machine.switch_to("air") machine.switch_to("air")
return return
# Jump buffer: player pressed jump just before landing # Jump buffer: player pressed jump just before landing
if machine.on_ground and machine.jump_buffer_time > 0.0: if machine.on_ground and machine.jump_buffer_time > 0.0 and machine.jump_cooldown_timer <= 0.0:
player.velocity.y = params.jump_velocity player.velocity.y = params.jump_velocity
machine.current_jump_count = 1 machine.current_jump_count = 1
machine.on_ground = false machine.on_ground = false
machine.jump_buffer_time = 0.0 machine.jump_buffer_time = 0.0
machine.register_chain_mechanic("jump") machine.register_chain_mechanic("jump")
machine.jump_cooldown_timer = params.jump_cooldown
if player.jump_player: if player.jump_player:
player.jump_player.play() player.jump_player.play()
machine.switch_to("air") machine.switch_to("air")
+2 -1
View File
@@ -99,7 +99,7 @@ func update(delta: float) -> void:
return return
# Jump out of slide # Jump out of slide
if machine.input_jump_just_pressed: if machine.input_jump_just_pressed and machine.jump_cooldown_timer <= 0.0:
player.velocity.y = params.jump_velocity player.velocity.y = params.jump_velocity
var hvel := Vector3(player.velocity.x, 0.0, player.velocity.z) var hvel := Vector3(player.velocity.x, 0.0, player.velocity.z)
if hvel.length_squared() > 0.01: if hvel.length_squared() > 0.01:
@@ -109,6 +109,7 @@ func update(delta: float) -> void:
player.velocity.x = dir.x * jump_speed player.velocity.x = dir.x * jump_speed
player.velocity.z = dir.z * jump_speed player.velocity.z = dir.z * jump_speed
machine.current_jump_count = 1 machine.current_jump_count = 1
machine.jump_cooldown_timer = params.jump_cooldown
machine.on_ground = false machine.on_ground = false
machine.register_chain_mechanic("slide_jump") machine.register_chain_mechanic("slide_jump")
machine.switch_to("air") machine.switch_to("air")
+3 -1
View File
@@ -48,12 +48,14 @@ func update(delta: float) -> void:
return return
# ── Jump off wall ───────────────────────────────────────────────────── # ── Jump off wall ─────────────────────────────────────────────────────
if machine.input_jump_just_pressed: if machine.input_jump_just_pressed and machine.jump_cooldown_timer <= 0.0:
var push_dir := machine.wall_normal * params.wall_run_jump_off_normal var push_dir := machine.wall_normal * params.wall_run_jump_off_normal
player.velocity = Vector3(push_dir.x, params.jump_velocity, push_dir.z) player.velocity = Vector3(push_dir.x, params.jump_velocity, push_dir.z)
machine.wall_normal = Vector3.ZERO machine.wall_normal = Vector3.ZERO
machine.wall_side = 0.0 machine.wall_side = 0.0
machine.wall_cooldown_timer = 0.3
machine.register_chain_mechanic("wall_cling_jump") machine.register_chain_mechanic("wall_cling_jump")
machine.jump_cooldown_timer = params.jump_cooldown
machine.switch_to("air") machine.switch_to("air")
return return
+2 -1
View File
@@ -98,7 +98,7 @@ func update(delta: float) -> void:
vel -= machine.wall_normal * 2.0 vel -= machine.wall_normal * 2.0
# ── Wall jump ───────────────────────────────────────────────────────── # ── Wall jump ─────────────────────────────────────────────────────────
if machine.input_jump_just_pressed: if machine.input_jump_just_pressed and machine.jump_cooldown_timer <= 0.0:
# Base jump off velocity on current preserved momentum # Base jump off velocity on current preserved momentum
var jump_vel: Vector3 = _current_tangent * _run_speed var jump_vel: Vector3 = _current_tangent * _run_speed
@@ -114,6 +114,7 @@ func update(delta: float) -> void:
machine.wall_side = 0.0 machine.wall_side = 0.0
machine.wall_cooldown_timer = 0.3 machine.wall_cooldown_timer = 0.3
machine.register_chain_mechanic("wall_jump") machine.register_chain_mechanic("wall_jump")
machine.jump_cooldown_timer = params.jump_cooldown
machine.switch_to("air") machine.switch_to("air")
return return