Sailing direction against wind update
This commit is contained in:
@@ -10,4 +10,4 @@ bevy = { version = "0.17.3", features = ["dynamic_linking"] }
|
||||
opt-level = 1
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
opt-level = 3
|
||||
|
||||
27
src/main.rs
27
src/main.rs
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user