diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 13:08:44 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 13:08:44 +0300 |
| commit | bfc283603ff9fc48b2dff3673a56f7ad481e1031 (patch) | |
| tree | 9e44fadbde26b49595f09a595f91e0e4580ea9a4 /crates/fparkan-runtime/src/player_gait.rs | |
| parent | 514136ca97191672ecd24173d1836cdc4d26493b (diff) | |
| download | fparkan-bfc283603ff9fc48b2dff3673a56f7ad481e1031.tar.xz fparkan-bfc283603ff9fc48b2dff3673a56f7ad481e1031.zip | |
feat(player): play footsteps on ground and building floors
Select the original step effects from the hero's Control rows. A footfall follows the accepted movement and the camera rhythm. The Firing Range window starts the ground sound on the step and stays quiet when the player stops.
Diffstat (limited to 'crates/fparkan-runtime/src/player_gait.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/player_gait.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/crates/fparkan-runtime/src/player_gait.rs b/crates/fparkan-runtime/src/player_gait.rs index 3b293d9a..fc564f63 100644 --- a/crates/fparkan-runtime/src/player_gait.rs +++ b/crates/fparkan-runtime/src/player_gait.rs @@ -1,4 +1,4 @@ -//! First-person motion of the walking hero's camera. +//! Camera motion and footfalls of the walking hero. use crate::{Engine, LoadedMissionState, StartingCockpit}; use fparkan_world::{transform_state, World}; @@ -11,17 +11,19 @@ pub(super) struct PlayerGait { previous: Option<(u32, [u32; 2])>, phase: f32, lift: f32, + pub(super) footfall: bool, } impl PlayerGait { fn advance(&mut self, clock_ms: u32, xy: [u32; 2]) { + self.footfall = false; let Some((previous_ms, previous_xy)) = self.previous.replace((clock_ms, xy)) else { return; }; let elapsed_ms = clock_ms.wrapping_sub(previous_ms).min(500) as f32; if previous_xy == xy { - let decay = (1.0 - elapsed_ms / (WALK_CYCLE_MS / 4.0)).clamp(0.0, 1.0); - self.lift *= decay; + let decay = CAMERA_LIFT * elapsed_ms / (WALK_CYCLE_MS / 4.0); + self.lift = self.lift.signum() * (self.lift.abs() - decay).max(0.0); if self.lift == 0.0 { self.phase = 0.0; } @@ -29,11 +31,22 @@ impl PlayerGait { } // shortcut: a sine matches the observed main component of the walk; // the native camera track and its response to movement speed are open. - self.phase = (self.phase + elapsed_ms / WALK_CYCLE_MS).fract(); + let next = self.phase + elapsed_ms / WALK_CYCLE_MS; + self.footfall = (next - 0.75).floor() > (self.phase - 0.75).floor(); + self.phase = next.fract(); self.lift = CAMERA_LIFT * (self.phase * std::f32::consts::TAU).sin(); } } +/// A foot contacting the accepted surface during the latest walking step. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct PlayerFootstep { + /// Position of the walker at ground contact, as IEEE-754 words. + pub position_bits: [u32; 3], + /// Whether building geometry supports the walker. + pub building_floor: bool, +} + pub(super) fn advance(mission: &mut LoadedMissionState, world: &World, now: u32) { let pose = mission .local_hero @@ -68,10 +81,13 @@ mod tests { assert_eq!(gait.lift, 0.0); gait.advance(224, [1, 0]); assert_eq!(gait.lift, CAMERA_LIFT); + assert!(!gait.footfall); gait.advance(448, [3, 0]); assert_eq!(gait.lift, -CAMERA_LIFT); + assert!(gait.footfall); gait.advance(504, [3, 0]); assert_eq!(gait.lift, -CAMERA_LIFT * 0.5); + assert!(!gait.footfall); gait.advance(616, [3, 0]); assert_eq!(gait.lift, 0.0); } |
