Merge branch 'juliancoffee/gliding-wind-fix' into 'master'

Fix client-side gliding

See merge request veloren/veloren!4349
This commit is contained in:
Illia Denysenko 2024-03-01 19:26:25 +00:00
commit 958cf048f4
3 changed files with 96 additions and 86 deletions

View File

@ -237,6 +237,9 @@ impl WeatherLerp {
.zip(old.iter().zip(new.iter()))
.for_each(|((_, current), ((_, old), (_, new)))| {
*current = CompressedWeather::lerp_unclamped(old, new, t);
// `local_wind` is set for all weather cells on the client,
// which will still be inaccurate outside the "local" area
current.wind = self.local_wind;
});
}
}

View File

@ -143,9 +143,7 @@ impl Body {
Vec3::zero()
} else {
let rel_flow_dir = Dir::new(rel_flow.0 / v_sq.sqrt());
0.5 * fluid_density
* v_sq
* match wings {
let power_vec = match wings {
Some(&Wings {
aspect_ratio,
planform_area,
@ -153,8 +151,8 @@ impl Body {
}) => {
if aspect_ratio > 25.0 {
tracing::warn!(
"Calculating lift for wings with an aspect ratio of {}. The \
formulas are only valid for aspect ratios below 25.",
"Calculating lift for wings with an aspect ratio of {}. The formulas \
are only valid for aspect ratios below 25.",
aspect_ratio
)
};
@ -207,7 +205,9 @@ impl Body {
},
_ => self.parasite_drag(scale) * *rel_flow_dir,
}
};
0.5 * fluid_density * v_sq * power_vec
}
}

View File

@ -225,7 +225,9 @@ fn simulated_wind_vel(
// === Ridge/Wave lift ===
let mut ridge_lift = {
let steepness = normal.angle_between(normal.with_z(0.)).max(0.5);
const RIDGE_LIFT_COEFF: f32 = 1.0;
let steepness = normal.angle_between(Vec3::unit_z());
// angle between normal and wind
let mut angle = wind_velocity.angle_between(normal.xy()); // 1.4 radians of zero
@ -235,7 +237,7 @@ fn simulated_wind_vel(
angle = (angle - 1.3).max(0.0);
// the ridge lift is based on the angle and the velocity of the wind
angle * steepness * wind_velocity.magnitude() * 2.0
angle * steepness * wind_velocity.magnitude() * RIDGE_LIFT_COEFF
};
// Cliffs mean more lift
@ -759,35 +761,40 @@ impl<'a> PhysicsData<'a> {
)
.join()
{
// Always reset air_vel to zero
let mut air_vel = Vec3::zero();
'simulation: {
// Don't simulate for non-gliding, for now
if !state.is_glide() {
continue;
break 'simulation;
}
let pos_2d = pos.0.as_().xy();
let chunk_pos: Vec2<i32> = pos_2d.wpos_to_cpos();
let Some(current_chunk) = &read.terrain.get_key(chunk_pos) else {
// oopsie
continue;
break 'simulation;
};
let meta = current_chunk.meta();
// Skip simulating for entites deeply under the ground
if pos.0.z < meta.alt() - 25.0 {
continue;
break 'simulation;
}
// If couldn't simulate wind for some reason, skip
let Ok(wind_vel) =
if let Ok(simulated_vel) =
simulated_wind_vel(pos, weather, &read.terrain, &read.time_of_day)
else {
continue;
{
air_vel = simulated_vel
};
}
phys.in_fluid = phys.in_fluid.map(|f| match f {
Fluid::Air { elevation, .. } => Fluid::Air {
vel: Vel(wind_vel),
vel: Vel(air_vel),
elevation,
},
fluid => fluid,