diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 7 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/mission_events.rs | 16 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/player_motion.rs | 21 |
3 files changed, 29 insertions, 15 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index a897839b..3b177b0a 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -18372,8 +18372,8 @@ mod tests { "{after:?}" ); for (time, slot, objective, plate) in [ - (4_001, 4, 1, [750.0_f32, 950.7, 45.88]), - (6_001, 5, 2, [950.7, 869.4, 69.98]), + (4_001, 4, 1, [750.0_f32, 950.7, 40.11]), + (6_001, 5, 2, [950.7, 869.4, 63.98]), (8_001, 3, 4, [1179.28, 1242.12, 101.60]), ] { if slot == 3 { @@ -18405,7 +18405,8 @@ mod tests { set_transform(&mut engine.world, cockpit.handle, pose).unwrap(); assert!(frame(&mut engine, 8_002).unwrap().mission_event.is_none()); assert_eq!(loaded_mission_script_outcome(&engine), active); - pose.position = [1175.335_f32, 1242.098, 79.0].map(f32::to_bits); + // Walking toward the portal on the stock lower tunnel's floor. + pose.position = [1173.7439_f32, 1243.9574, 74.78949].map(f32::to_bits); set_transform(&mut engine.world, cockpit.handle, pose).unwrap(); let event = frame(&mut engine, 8_003).unwrap().mission_event.unwrap(); assert!(event.stop.is_none(), "{event:?}"); diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs index fc02236d..62564970 100644 --- a/crates/fparkan-runtime/src/mission_events.rs +++ b/crates/fparkan-runtime/src/mission_events.rs @@ -716,17 +716,22 @@ impl LoadedMissionState { if self.boarding.is_some() || self.script_host_mode != super::MissionMode::SingleMission { return false; } - let hero = self.object_drafts.iter().find(|draft| { + let Some(hero) = self.object_drafts.iter().find(|draft| { draft.unit_dat_header_flags == Some(super::HERO_UNIT_CLASS) && draft.raw_after_resource == 0 - }); + }) else { + return false; + }; let Some(hero_position) = hero - .and_then(|draft| handle_by_original_id(world, draft.original_id?)) + .original_id + .and_then(|id| handle_by_original_id(world, id)) .and_then(|hero| transform_state(world, hero).ok()) .map(|pose| pose.position.map(f32::from_bits)) else { return false; }; + let clearance = crate::player_motion::spawn_floor_clearance(&self.terrain, hero.position) + .unwrap_or_default(); self.object_drafts.iter().enumerate().any(|(index, draft)| { if draft.unit_dat_header_flags != Some(MAIN_TELEPORT_CLASS) { return false; @@ -755,8 +760,11 @@ impl LoadedMissionState { }) else { return false; }; - // shortcut: static node poses and the ordinary Res17 volume until animated triggers are wired. + // shortcut: use the authored spawn clearance to project a + // floor-level walking pose into the native contact volume. + let [x, y, z] = hero_position; inside_exit_volume(center, hero_position) + || inside_exit_volume(center, [x, y, z + clearance]) })) }; hit() == Some(true) diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs index 5a999546..18bd2d68 100644 --- a/crates/fparkan-runtime/src/player_motion.rs +++ b/crates/fparkan-runtime/src/player_motion.rs @@ -32,6 +32,18 @@ const WATER_SURFACE: u32 = 0x0002_0000; const WALK_COLLISION_DISTANCE: f32 = 0.16; const WALK_SPEED_FALLBACK: f32 = 8.0; +pub(super) fn spawn_floor_clearance( + terrain: &TerrainWorld, + [x, y, z]: [f32; 3], +) -> Result<f32, EngineError> { + let floor = terrain + .height_at([x, y]) + .map_err(|error| EngineError::Movement(error.to_string()))?; + Ok(floor.map_or(FLOOR_CLEARANCE, |floor| { + (z - floor).clamp(FLOOR_CLEARANCE, STEP_DOWN) + })) +} + /// Player controls sampled once for a simulation step. #[derive(Clone, Copy, Debug, Default)] pub struct PlayerMotion { @@ -433,14 +445,7 @@ fn plan_player_steps( let mut max_floor_clearance = FLOOR_CLEARANCE; if !flying && input.movement != [0.0; 2] { if let Some(draft) = mission.object_drafts.get(cockpit.object_index) { - let [x, y, z] = draft.position; - if let Some(ground) = mission - .terrain - .height_at([x, y]) - .map_err(|err| EngineError::Movement(err.to_string()))? - { - max_floor_clearance = (z - ground).clamp(FLOOR_CLEARANCE, STEP_DOWN); - } + max_floor_clearance = spawn_floor_clearance(&mission.terrain, draft.position)?; } } let Some(resolve) = resolve else { |
