Compare commits

...

2 Commits

Author SHA1 Message Date
JP Stringham
92c83c7b30 Merge branch 'main' of ssh://192.168.7.152:3001/jp/sailing 2025-12-07 11:45:15 -05:00
JP Stringham
711250d87a Sailing direction against wind update 2025-12-07 11:44:56 -05:00
2 changed files with 17 additions and 12 deletions

View File

@@ -10,4 +10,4 @@ bevy = { version = "0.17.3", features = ["dynamic_linking"] }
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
opt-level = 3

View File

@@ -133,24 +133,29 @@ fn player_physics(
physics.speed *= 0.99;
let sail_speed_x = physics.heading.sin();
let sail_speed_y = physics.heading.cos();
// using just the heading is incorrect, as the sail adjusts based on heading vs wind
let sail_dir_x = physics.heading.sin();
let sail_dir_y = physics.heading.cos();
let wind_speed_x = wind_conditions.direction.sin();
let wind_speed_y = wind_conditions.direction.cos();
let wind_dir_x = wind_conditions.direction.sin();
let wind_dir_y = wind_conditions.direction.cos();
let sail_speed_vec = Vec2 {
x: sail_speed_x,
y: sail_speed_y,
let sail_dir_vec = Vec2 {
x: sail_dir_x,
y: sail_dir_y,
};
let wind_speed_vec = Vec2 {
x: wind_speed_x,
y: wind_speed_y,
let wind_dir_vec = Vec2 {
x: wind_dir_x,
y: wind_dir_y,
};
// technically you could put your sail out and try to go backwards but..
// 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. {
physics.speed += 0.01 * boat_state.sail_extension * sail_strength;