Sailing direction against wind update

This commit is contained in:
JP Stringham
2025-12-07 11:44:56 -05:00
parent 8a3b485ece
commit 711250d87a
2 changed files with 17 additions and 12 deletions

View File

@@ -133,24 +133,29 @@ fn player_physics(
physics.speed *= 0.99; physics.speed *= 0.99;
let sail_speed_x = physics.heading.sin(); // using just the heading is incorrect, as the sail adjusts based on heading vs wind
let sail_speed_y = physics.heading.cos(); let sail_dir_x = physics.heading.sin();
let sail_dir_y = physics.heading.cos();
let wind_speed_x = wind_conditions.direction.sin(); let wind_dir_x = wind_conditions.direction.sin();
let wind_speed_y = wind_conditions.direction.cos(); let wind_dir_y = wind_conditions.direction.cos();
let sail_speed_vec = Vec2 { let sail_dir_vec = Vec2 {
x: sail_speed_x, x: sail_dir_x,
y: sail_speed_y, y: sail_dir_y,
}; };
let wind_speed_vec = Vec2 { let wind_dir_vec = Vec2 {
x: wind_speed_x, x: wind_dir_x,
y: wind_speed_y, y: wind_dir_y,
}; };
// technically you could put your sail out and try to go backwards but.. // technically you could put your sail out and try to go backwards but..
// let's not tackle that (Yet?) // let's not tackle that (Yet?)
let sail_strength = sail_speed_vec.dot(wind_speed_vec).clamp(0., 1.); let sail_strength = sail_dir_vec
.dot(wind_dir_vec)
.clamp(-0.8, 1.)
.remap(-0.8, 1., 0., 1.)
* wind_conditions.strength;
if boat_state.sail_extension > 0. { if boat_state.sail_extension > 0. {
physics.speed += 0.01 * boat_state.sail_extension * sail_strength; physics.speed += 0.01 * boat_state.sail_extension * sail_strength;