Feat/2 weapons foundation #6
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -60,6 +61,10 @@ func _physics_process(delta: float) -> void:
|
|||||||
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:
|
||||||
chain_timer -= delta
|
chain_timer -= delta
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user