aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 13:21:58 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 13:21:58 +0300
commitb201e339c804aba7b9ef023833b7aee4fab96d96 (patch)
treed479496aeacafd1dc144ea52c5bd129586668b49
parentbfc283603ff9fc48b2dff3673a56f7ad481e1031 (diff)
downloadfparkan-b201e339c804aba7b9ef023833b7aee4fab96d96.tar.xz
fparkan-b201e339c804aba7b9ef023833b7aee4fab96d96.zip
fix(player): use the Control forward limit for walking
Read the live Control profile for walking along the body's heading. The stock Firing Range window advances at roughly 14 units per second while the key is held. Size collision sweeps from actual requested displacement so the stock factory entrance, passage and exit still work.
-rw-r--r--apps/fparkan-game/src/main.rs2
-rw-r--r--apps/fparkan-game/src/player_collision.rs4
-rw-r--r--crates/fparkan-runtime/src/lib.rs16
-rw-r--r--crates/fparkan-runtime/src/player_motion.rs51
-rw-r--r--docs/appendices/knowledge-boundaries.md2
-rw-r--r--docs/tomes/06-behavior.md5
6 files changed, 61 insertions, 19 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 6a1a046a..1c55502b 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -14070,7 +14070,7 @@ mod tests {
&engine,
cockpit,
PlayerMotion {
- movement: [(x - hx) / distance, (y - hy) / distance],
+ movement: [(x - hx) / distance, (y - hy) / distance * (8.0 / 14.0)],
delta_seconds: distance.min(8.0 * 0.292) / 8.0,
..PlayerMotion::default()
},
diff --git a/apps/fparkan-game/src/player_collision.rs b/apps/fparkan-game/src/player_collision.rs
index adf6f339..5e1ed12e 100644
--- a/apps/fparkan-game/src/player_collision.rs
+++ b/apps/fparkan-game/src/player_collision.rs
@@ -227,7 +227,7 @@ mod tests {
&engine,
cockpit,
PlayerMotion {
- movement: [dx * cos + dy * sin, dy * cos - dx * sin],
+ movement: [dx * cos + dy * sin, (dy * cos - dx * sin) * (8.0 / 14.0)],
delta_seconds: distance.min(0.8) / 8.0,
..Default::default()
},
@@ -386,7 +386,7 @@ mod tests {
&engine,
cockpit,
PlayerMotion {
- movement: [dx * cos + dy * sin, dy * cos - dx * sin],
+ movement: [dx * cos + dy * sin, (dy * cos - dx * sin) * (8.0 / 14.0)],
delta_seconds: distance.min(0.8) / 8.0,
..Default::default()
},
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 23e18cae..f162b074 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -18011,7 +18011,19 @@ mod tests {
pose(&frame_with_player_motion(&mut engine, 200, cockpit, proposed, false).unwrap());
let [x0, y0, z0] = original.position.map(f32::from_bits);
let [x1, y1, z1] = walked.position.map(f32::from_bits);
- assert!(((x1 - x0).hypot(y1 - y0) - 0.8).abs() < 1e-4);
+ let runtime_speed = f32::from_bits(
+ loaded_mission_control_device_tables(&engine)
+ .unwrap()
+ .iter()
+ .find(|table| table.handle == cockpit.handle)
+ .unwrap()
+ .owner_profile
+ .as_ref()
+ .unwrap()
+ .current_words[7],
+ );
+ assert!((runtime_speed - 14.0).abs() < 0.01);
+ assert!(((x1 - x0).hypot(y1 - y0) - runtime_speed * 0.1).abs() < 1e-4);
let ground = |xy| {
loaded_terrain(&engine)
.unwrap()
@@ -18034,7 +18046,7 @@ mod tests {
pose(&frame_with_player_motion(&mut engine, 400, cockpit, slow_frame, false).unwrap())
.position
.map(f32::from_bits);
- assert!(((x2 - x1).hypot(y2 - y1) - 1.6).abs() < 1e-4);
+ assert!(((x2 - x1).hypot(y2 - y1) - runtime_speed * 0.2).abs() < 1e-4);
set_transform(&mut engine.world, cockpit.handle, walked).unwrap();
let mut split = walked;
for clock_ms in [500, 600] {
diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs
index b21efd5b..0b5ef029 100644
--- a/crates/fparkan-runtime/src/player_motion.rs
+++ b/crates/fparkan-runtime/src/player_motion.rs
@@ -28,7 +28,9 @@ const STEP_DOWN: f32 = 2.0;
const FLOOR_CLEARANCE: f32 = 0.02;
const WATER_SURFACE: u32 = 0x0002_0000;
// shortcut: sample the temporary floor probe at most 0.16 units apart until native collision is wired.
-const WALK_COLLISION_INTERVAL: f32 = 0.02;
+const WALK_COLLISION_DISTANCE: f32 = 0.16;
+const WALK_SPEED_FALLBACK: f32 = 8.0;
+const FLIGHT_SPEED_FALLBACK: f32 = 40.0;
/// Player controls sampled once for a simulation step.
#[derive(Clone, Copy, Debug, Default)]
@@ -396,6 +398,21 @@ fn plan_player_steps(
if !input.delta_seconds.is_finite() || input.delta_seconds < 0.0 {
return Err(EngineError::Movement("invalid player step".into()));
}
+ let speeds = if flying {
+ [FLIGHT_SPEED_FALLBACK; 2]
+ } else if mission.local_hero == Some(cockpit.handle) {
+ let forward = mission
+ .control_device_tables
+ .iter()
+ .find(|table| table.handle == cockpit.handle)
+ .and_then(|table| table.owner_profile.as_ref())
+ .map(|profile| f32::from_bits(profile.current_words[7]))
+ .filter(|speed| speed.is_finite() && *speed >= 0.0)
+ .unwrap_or(WALK_SPEED_FALLBACK);
+ [WALK_SPEED_FALLBACK, forward]
+ } else {
+ [WALK_SPEED_FALLBACK; 2]
+ };
// shortcut: use the outdoor spawn clearance until the native walking collider is wired.
let mut max_floor_clearance = FLOOR_CLEARANCE;
if !flying && input.movement != [0.0; 2] {
@@ -411,20 +428,21 @@ fn plan_player_steps(
}
}
let Some(resolve) = resolve else {
- let mut step = plan_motion(&mission.terrain, pose, pitch, flying, input)?;
+ let mut step = plan_motion(&mission.terrain, pose, pitch, flying, speeds, input)?;
step.max_floor_clearance = max_floor_clearance;
return Ok(Some(step));
};
let count = if !flying && input.movement != [0.0; 2] {
// shortcut: bound movement after a long stall while the scene uses the render clock.
input.delta_seconds = input.delta_seconds.min(0.5);
- (input.delta_seconds / WALK_COLLISION_INTERVAL).ceil() as u32
+ let [across, along] = body_velocity(input.movement, speeds);
+ (input.delta_seconds * across.hypot(along) / WALK_COLLISION_DISTANCE).ceil() as u32
} else {
1
}
.max(1);
input.delta_seconds /= count as f32;
- let mut step = plan_motion(&mission.terrain, pose, pitch, flying, input)?;
+ let mut step = plan_motion(&mission.terrain, pose, pitch, flying, speeds, input)?;
let mut previous = pose;
let mut previous_surface = WalkingSurface::Ground;
input.mouse_x = 0.0;
@@ -436,6 +454,7 @@ fn plan_player_steps(
previous,
f32::from_bits(step.pitch_bits),
flying,
+ speeds,
input,
)?;
}
@@ -457,11 +476,21 @@ fn plan_player_steps(
Ok(Some(step))
}
+fn body_velocity(movement: [f32; 2], [side_speed, forward_speed]: [f32; 2]) -> [f32; 2] {
+ let [right, forward] = movement.map(|axis| axis.clamp(-1.0, 1.0));
+ let length = right.hypot(forward).max(1.0);
+ [
+ right * side_speed / length,
+ forward * forward_speed / length,
+ ]
+}
+
fn plan_motion(
terrain: &TerrainWorld,
mut pose: TransformState,
pitch: f32,
flying: bool,
+ speeds: [f32; 2],
input: PlayerMotion,
) -> Result<PlayerMotionStep, EngineError> {
let from = pose.position.map(f32::from_bits);
@@ -483,8 +512,7 @@ fn plan_motion(
{
return Err(EngineError::Movement("invalid player step".into()));
}
- // shortcut: use constant walk speed and mouse gain until native Control
- // acceleration and mouse sensitivity are measured.
+ // shortcut: use constant mouse gain until native sensitivity is measured.
let yaw = if input.mouse_x != 0.0 {
let yaw = (yaw - input.mouse_x.clamp(-1_000.0, 1_000.0) * 0.003)
.rem_euclid(std::f32::consts::TAU);
@@ -493,14 +521,13 @@ fn plan_motion(
} else {
yaw
};
- let [right, forward] = input.movement.map(|axis| axis.clamp(-1.0, 1.0));
- // shortcut: constant flight rates until thrust, clearance and inertia are measured.
- let speed = if flying { 40.0 } else { 8.0 };
- let distance = speed * input.delta_seconds / right.hypot(forward).max(1.0);
+ // shortcut: apply the requested velocity immediately until native acceleration is known.
+ let [across, along] =
+ body_velocity(input.movement, speeds).map(|speed| speed * input.delta_seconds);
let (sin, cos) = yaw.sin_cos();
let xy = [
- from[0] + (cos * right - sin * forward) * distance,
- from[1] + (sin * right + cos * forward) * distance,
+ from[0] + cos * across - sin * along,
+ from[1] + sin * across + cos * along,
];
let climb = if flying {
input.climb.clamp(-1.0, 1.0) * (16.0 * input.delta_seconds)
diff --git a/docs/appendices/knowledge-boundaries.md b/docs/appendices/knowledge-boundaries.md
index 7548577e..dd5fd62f 100644
--- a/docs/appendices/knowledge-boundaries.md
+++ b/docs/appendices/knowledge-boundaries.md
@@ -137,7 +137,7 @@ authoring API без динамического подтверждения.
`cockpit_pose_approx` отмечает расчёт кабины по ресурсной позе.
Вертикальное качание героя воспроизводит измеренный период. Форма
смещения, боковое качание и зависимость от скорости открыты.
-`player_motion_approx` отмечает постоянную скорость, приближённую
+`player_motion_approx` отмечает мгновенный набор скорости, боковой ход, приближённую
чувствительность и проверку корпуса короткими отрезками. После задержки
дольше полусекунды ходьба учитывает только первые 500 мс. `cockpit_aim_approx`
отмечает приближённый вертикальный угол камеры и выбор позы башни.
diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md
index c8b9cab4..c04793e0 100644
--- a/docs/tomes/06-behavior.md
+++ b/docs/tomes/06-behavior.md
@@ -2380,7 +2380,10 @@ Control получает world-interface Terrain и использует повÐ
На каждом шаге FParkan переводит направления из осей корпуса в мировые
координаты, измеряет высоту поверхности на старой и новой позиции и
-сохраняет высоту героя над поверхностью. Дальность шага учитывает весь
+сохраняет высоту героя над поверхностью. Ход вперёд и назад использует
+продольный предел из слова 7 действующего профиля Control. У героя
+«Огневого рубежа» это около 14 единиц в секунду. Разгон и боковая скорость
+пока приближённые. Дальность шага учитывает весь
интервал игровых часов, поэтому на ровном участке один кадр в 200 мс
даёт то же смещение, что два кадра по 100 мс. Например, при подъёме земли
на две единицы корень героя тоже поднимется на две единицы. При переходе на