diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 19:37:09 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 19:37:09 +0300 |
| commit | 1f366ac0d39a3b1f0b19721ed78936bad1e504dd (patch) | |
| tree | 431e3cebf1f3c96af086e928b3acdae53df48d1c /apps | |
| parent | f3d1b4d2aff8e47003626129641c36e44c7fb040 (diff) | |
| download | fparkan-1f366ac0d39a3b1f0b19721ed78936bad1e504dd.tar.xz fparkan-1f366ac0d39a3b1f0b19721ed78936bad1e504dd.zip | |
fix(movement): carry hero walking velocity between ticks
Take both horizontal limits and acceleration from the active Control
profile. Apply the measured slope braking after the input update and
clear velocity on a blocking wall, teleport or boarding.
Keep the terrain limit during geometric sweeps so momentum cannot skip
a narrow cliff. In the stock Firing Line window the hero reached the
slope, stopped at its foot, backed away, and coasted on key release.
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 6 | ||||
| -rw-r--r-- | apps/fparkan-game/src/player_collision.rs | 63 |
2 files changed, 39 insertions, 30 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index b00605ab..a328ccad 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -14055,11 +14055,7 @@ mod tests { let step = plan_player_motion_with_collision( &engine, cockpit, - PlayerMotion { - movement: [(x - hx) / distance, (y - hy) / distance * (8.0 / 14.0)], - delta_seconds: distance.min(8.0 * 0.292) / 8.0, - ..PlayerMotion::default() - }, + player_collision::walk_toward(hero, [x, y], 2.0), |step| { app.resolve_player_building_step(step) .map_err(EngineError::Movement) diff --git a/apps/fparkan-game/src/player_collision.rs b/apps/fparkan-game/src/player_collision.rs index 802e3bef..8b673e80 100644 --- a/apps/fparkan-game/src/player_collision.rs +++ b/apps/fparkan-game/src/player_collision.rs @@ -71,6 +71,33 @@ impl StaticVulkanApp { } #[cfg(test)] +pub(crate) fn walk_toward( + pose: fparkan_world::TransformState, + target: [f32; 2], + max_step: f32, +) -> fparkan_runtime::PlayerMotion { + let [x, y, _] = pose.position.map(f32::from_bits); + let [dx, dy] = [target[0] - x, target[1] - y]; + let yaw = f32::from_bits(pose.orientation[2]); + let wanted = (-dx).atan2(dy); + let turn = (yaw - wanted + std::f32::consts::PI).rem_euclid(std::f32::consts::TAU) + - std::f32::consts::PI; + // Use normal mouse and forward input. An about-face may use a second sample + // because the game clamps mouse deltas. + let can_walk = turn.abs() <= 3.0; + fparkan_runtime::PlayerMotion { + mouse_x: turn / 0.003, + movement: [0.0, f32::from(can_walk)], + delta_seconds: if can_walk { + dx.hypot(dy).min(max_step) / 14.0 + } else { + 0.0 + }, + ..Default::default() + } +} + +#[cfg(test)] mod tests { use crate::tests::clock_test_app; use crate::*; @@ -169,6 +196,8 @@ mod tests { }; let mut now = 0; let mut hero = pose(step_mission_frame(&mut engine, now).unwrap()); + let [spawn_x, spawn_y, spawn_z] = hero.position.map(f32::from_bits); + let spawn_clearance = spawn_z - app.terrain.height_at([spawn_x, spawn_y]).unwrap().unwrap(); let mut door_blends = Vec::new(); let mut footstep_surfaces = [false; 2]; for (index, [x, y]) in route @@ -184,9 +213,6 @@ mod tests { if distance <= 0.04 { break; } - let [dx, dy] = [(x - hx) / distance, (y - hy) / distance]; - let yaw = f32::from_bits(hero.orientation[2]); - let (sin, cos) = yaw.sin_cos(); let mut node_times: Vec<_> = fparkan_runtime::initial_component_node_times( model.node_count, &control.bindings, @@ -222,11 +248,7 @@ mod tests { let motion = plan_player_motion_with_collision( &engine, cockpit, - PlayerMotion { - movement: [dx * cos + dy * sin, (dy * cos - dx * sin) * (8.0 / 14.0)], - delta_seconds: distance.min(0.8) / 8.0, - ..Default::default() - }, + super::walk_toward(hero, [x, y], 0.8), |step| { app.resolve_player_building_step(step) .map_err(EngineError::Movement) @@ -274,8 +296,9 @@ mod tests { assert_eq!(footstep_surfaces, [true, true]); let ground = app.terrain.height_at([x, y]).unwrap().unwrap(); assert!( - (ground..ground + 1.0).contains(&z), - "factory exit at {z}, ground {ground}" + (z - ground - spawn_clearance).abs() < 0.02, + "factory exit clearance {}, stock outdoor clearance {spawn_clearance}", + z - ground ); } @@ -374,18 +397,10 @@ mod tests { break; } assert!(index < 899, "blocked for waypoint {dy}: {hx}, {hy}, {hz}"); - let yaw = f32::from_bits(hero.orientation[2]); - let (sin, cos) = yaw.sin_cos(); - let dx = (x - hx) / distance; - let dy = (y - hy) / distance; let step = plan_player_motion_with_collision( &engine, cockpit, - PlayerMotion { - movement: [dx * cos + dy * sin, (dy * cos - dx * sin) * (8.0 / 14.0)], - delta_seconds: distance.min(0.8) / 8.0, - ..Default::default() - }, + super::walk_toward(hero, [x, y], 0.8), |step| { app.resolve_player_building_step(step) .map_err(EngineError::Movement) @@ -397,12 +412,10 @@ mod tests { hero = pose(frame_with_player_motion(&mut engine, now, cockpit, step, false).unwrap()); let new_z = f32::from_bits(hero.position[2]); - if dy >= -34.0 { - assert!( - (new_z - hz).abs() < 0.3, - "height jump at {hx} {hy}: {hz} -> {new_z}" - ); - } + assert!( + (new_z - hz).abs() < 0.3, + "height jump at {hx} {hy}: {hz} -> {new_z}" + ); } } } |
