Audio (all CC0 — Kenney packs + OpenGameArt, see assets/sounds/SOURCES.md): - Replace every procedural synth WAV with forged sounds (ffmpeg pitch/layer mixes): distinct fire sounds per weapon with 2-3 variations, explosions, footsteps x5, land/jump/dash/vault, knife swing, hit/kill confirms, bullet impacts, reload, flight loops, UI hover/click/confirm/error, match jingles, menu music - AudioManager.stream_for(): AudioStreamRandomizer per sound id — every weapon now gets variation + pitch randomization on each shot - Explosions and bullet impacts play positional audio; landing has its own sound instead of a pitched footstep; ambient wind bed on every map Visuals: - ExplosionVFX: shared cel-shaded burst (white-hot stepped core, ink shockwave ring, star spikes, flat smoke puffs) replaces the orange sphere in both local and remote-replay paths - Comic star muzzle flashes on all weapons; unified cel tracer bolts with ink outlines across hitscan/shotgun/remote paths - Impact decals: hard-stepped ink-splat gradients instead of soft airbrush - Toon shading on first-person view models + arms, third-person weapons, and the procedural humanoid fallback (no hull outlines on FBX weapons — their hard normals tear the inverted hull) - Fix: giant soft "blob" highlight on floors — toon rim/specular disabled on level-geometry materials (pre-existing artifact since the cel commit) - Fix: own third-person weapon rendered into the first-person camera (shadows-only now covers first_person_mode) UI: - UITheme: comic theme on the root window — Bangers display font (OFL), paper panels with thick ink borders + hard drop shadows, papaya accent, themed buttons/inputs/popups; hover/click sounds on all menu buttons - Main menu: tilted comic wordmark, sunset toon diorama, looping menu music - Match HUD: themed scoreboard/killfeed/kill counter Viewports: - 4x MSAA project-wide + viewmodel/diorama viewports (crisp ink lines) - Viewmodel camera near plane 0.01; third-person camera FOV syncs settings - debug/visual_capture.gd: dev tool to screenshot menu + level for review Verified: 11/11 movement tests, spawn smoke test 0 failures, before/after screenshot comparison of menu and level. Co-Authored-By: Claude Fable 5 <[email protected]>
184 lines
7.4 KiB
GDScript
184 lines
7.4 KiB
GDScript
extends Node
|
|
class_name StateGround
|
|
|
|
var machine: MovementStateMachine
|
|
var params: MovementParams:
|
|
get: return machine.params
|
|
|
|
var _footstep_timer: float = 0.0
|
|
|
|
|
|
func enter(_data: Dictionary = {}) -> void:
|
|
machine.on_ground = true
|
|
machine.current_jump_count = 0
|
|
machine.can_wall_climb = true
|
|
# Clear wall tilt on landing
|
|
var rig = _get_camera_rig()
|
|
if rig:
|
|
rig.clear_wall_tilt()
|
|
|
|
|
|
func exit() -> void:
|
|
pass
|
|
|
|
|
|
func update(delta: float) -> void:
|
|
var player := machine.player
|
|
var vel: Vector3 = player.velocity
|
|
|
|
# ── Jump (direct press w/ coyote, or buffered from before landing) ────
|
|
if machine.jump_cooldown_timer <= 0.0:
|
|
var pressed := machine.input_jump_just_pressed and machine.coyote_timer > 0.0
|
|
var buffered := machine.on_ground and machine.jump_buffer_time > 0.0
|
|
if pressed or buffered:
|
|
machine.do_jump()
|
|
machine.switch_to("air")
|
|
return
|
|
|
|
# ── Slide (crouch while moving fast enough) ───────────────────────────
|
|
if machine.input_crouch and machine.slide_cooldown_timer <= 0.0:
|
|
var hspeed := Vector3(player.velocity.x, 0.0, player.velocity.z).length()
|
|
if hspeed > params.slide_min_speed + 1.0:
|
|
machine.switch_to("slide")
|
|
return
|
|
|
|
# ── Determine target speed ────────────────────────────────────────────
|
|
var wish_dir: Vector3 = machine.wish_dir_world
|
|
var speed := params.walk_speed
|
|
if machine.input_crouch:
|
|
speed = params.crouch_speed
|
|
var effective_speed := machine.get_effective_speed(speed)
|
|
|
|
# ── Horizontal movement (exponential interpolation for smoothness) ───
|
|
var hvel := Vector3(vel.x, 0.0, vel.z)
|
|
var target_vel := wish_dir * effective_speed
|
|
|
|
if wish_dir.length_squared() > 0.0:
|
|
hvel = hvel.lerp(target_vel, 1.0 - exp(-params.ground_acceleration * delta))
|
|
else:
|
|
hvel = hvel.lerp(Vector3.ZERO, 1.0 - exp(-params.ground_deceleration * delta))
|
|
|
|
vel.x = hvel.x
|
|
vel.z = hvel.z
|
|
|
|
# ── Gravity / floor snap ──────────────────────────────────────────────
|
|
if not player.is_on_floor():
|
|
vel.y -= params.gravity * delta
|
|
else:
|
|
# Snap to floor: small downward velocity keeps is_on_floor() stable
|
|
# ONLY if we aren't being launched upward by an impulse!
|
|
if vel.y <= 0.0:
|
|
vel.y = -0.5
|
|
|
|
player.velocity = vel
|
|
player.move_and_slide()
|
|
|
|
# ── Stair Stepping ────────────────────────────────────────────────────
|
|
if wish_dir.length_squared() > 0.01 and not machine.input_crouch:
|
|
_try_step_up(player, wish_dir, hvel)
|
|
|
|
var current_hspeed = Vector2(player.velocity.x, player.velocity.z).length()
|
|
if current_hspeed > 1.0 and player.is_on_floor():
|
|
_footstep_timer -= delta
|
|
if _footstep_timer <= 0.0:
|
|
if player.footstep_player:
|
|
# Random sample + slight pitch variation so steps don't machine-gun.
|
|
if "footstep_streams" in player and not player.footstep_streams.is_empty():
|
|
player.footstep_player.stream = player.footstep_streams.pick_random()
|
|
player.footstep_player.pitch_scale = randf_range(0.92, 1.08)
|
|
player.footstep_player.volume_db = -6.0
|
|
player.footstep_player.play()
|
|
_footstep_timer = max(0.2, 3.0 / current_hspeed)
|
|
else:
|
|
_footstep_timer = 0.0
|
|
|
|
# ── Update ground status ──────────────────────────────────────────────
|
|
if player.is_on_floor():
|
|
machine.on_ground = true
|
|
machine.current_jump_count = 0
|
|
else:
|
|
machine.on_ground = false
|
|
|
|
# ── Launch or Falling off ledge → air state ───────────────────────────
|
|
if not machine.on_ground:
|
|
if player.velocity.y > 0.0 or machine.coyote_timer <= 0.0:
|
|
machine.switch_to("air")
|
|
return
|
|
|
|
# ── Wall interaction (Vault, Climb) ───────────────────────────────────
|
|
if machine.input_dir.length() > 0.1 and machine.input_dir.y <= 0.0 \
|
|
and machine.wall_cooldown_timer <= 0.0 and not machine.input_crouch:
|
|
var fwd_wall = machine.detect_wall_forward()
|
|
if fwd_wall.hit:
|
|
var hspeed := Vector3(player.velocity.x, 0.0, player.velocity.z).length()
|
|
if fwd_wall.is_short and hspeed > 3.0:
|
|
machine.do_vault()
|
|
machine.switch_to("air")
|
|
return
|
|
elif not fwd_wall.is_short:
|
|
# Check if moving directly into wall and looking generally towards it
|
|
var look_dir := -player.global_transform.basis.z
|
|
var looking_towards := look_dir.dot(-fwd_wall.normal) > 0.0
|
|
var moving_towards := machine.wish_dir_world.dot(-fwd_wall.normal) > cos(deg_to_rad(params.wall_climb_max_angle))
|
|
|
|
if looking_towards and moving_towards and machine.can_wall_climb:
|
|
machine.wall_normal = fwd_wall.normal
|
|
machine.switch_to("wall_climb")
|
|
return
|
|
|
|
# ── Dash ──────────────────────────────────────────────────────────────
|
|
if machine.input_dash and machine.can_dash():
|
|
machine.switch_to("dash")
|
|
return
|
|
|
|
|
|
func _try_step_up(player: CharacterBody3D, wish_dir: Vector3, hvel: Vector3) -> void:
|
|
for i in range(player.get_slide_collision_count()):
|
|
var col = player.get_slide_collision(i)
|
|
if abs(col.get_normal().y) < 0.3: # Hit a wall
|
|
var max_step_height = 0.95
|
|
var space_state = player.get_world_3d().direct_space_state
|
|
var feet_y = player.global_position.y - (machine.original_capsule_height / 2.0)
|
|
|
|
# Raycast down from above the step
|
|
var fwd = wish_dir.normalized()
|
|
var ray_start = player.global_position + fwd * 0.65
|
|
ray_start.y = feet_y + max_step_height + 0.1
|
|
var ray_end = ray_start - Vector3.UP * (max_step_height + 0.2)
|
|
|
|
var ray = PhysicsRayQueryParameters3D.create(ray_start, ray_end)
|
|
ray.exclude = [player.get_rid()]
|
|
var hit = space_state.intersect_ray(ray)
|
|
|
|
if not hit.is_empty() and hit.normal.y > 0.7:
|
|
var step_height = hit.position.y - feet_y
|
|
if step_height > 0.01 and step_height <= max_step_height:
|
|
# Check if we have headroom to move up
|
|
var head_ray_start = player.global_position
|
|
head_ray_start.y += (machine.original_capsule_height / 2.0)
|
|
var head_ray_end = head_ray_start + Vector3.UP * (step_height + 0.1)
|
|
var head_ray = PhysicsRayQueryParameters3D.create(head_ray_start, head_ray_end)
|
|
head_ray.exclude = [player.get_rid()]
|
|
|
|
if space_state.intersect_ray(head_ray).is_empty():
|
|
# Check if there is enough space to move forward after stepping up
|
|
var test_transform = player.global_transform
|
|
test_transform.origin.y += step_height + 0.05
|
|
if not player.test_move(test_transform, fwd * 0.15):
|
|
# We can safely step up
|
|
player.global_position.y += step_height + 0.01
|
|
if player.head_pivot and player.head_pivot.has_method("add_step_offset"):
|
|
player.head_pivot.add_step_offset(-(step_height + 0.01))
|
|
# Push slightly forward to get onto the step
|
|
player.global_position += fwd * 0.1
|
|
# Restore horizontal velocity that was lost from hitting the wall
|
|
player.velocity.x = hvel.x
|
|
player.velocity.z = hvel.z
|
|
break
|
|
|
|
|
|
func _get_camera_rig():
|
|
if machine.player and machine.player.has_node("HeadPivot"):
|
|
return machine.player.get_node("HeadPivot")
|
|
return null
|