|
@@ -1,4 +1,4 @@
|
|
|
-use crate::body::{Rotation, Velocity};
|
|
|
|
|
|
|
+use crate::body::{Rotation, Thrust, Velocity};
|
|
|
use bevy::prelude::*;
|
|
use bevy::prelude::*;
|
|
|
|
|
|
|
|
pub struct ShipsPlugin;
|
|
pub struct ShipsPlugin;
|
|
@@ -13,7 +13,7 @@ struct Name(String);
|
|
|
struct TelemetryTimer(Timer);
|
|
struct TelemetryTimer(Timer);
|
|
|
|
|
|
|
|
const RCS_THRUST: f32 = 0.5;
|
|
const RCS_THRUST: f32 = 0.5;
|
|
|
-const MAIN_THRUST: f32 = 1.0;
|
|
|
|
|
|
|
+const MAIN_THRUST: f32 = 0.1;
|
|
|
|
|
|
|
|
impl Plugin for ShipsPlugin {
|
|
impl Plugin for ShipsPlugin {
|
|
|
fn build(&self, app: &mut App) {
|
|
fn build(&self, app: &mut App) {
|
|
@@ -39,27 +39,31 @@ fn spawn_ships(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
|
Ship,
|
|
Ship,
|
|
|
Name("Player".to_string()),
|
|
Name("Player".to_string()),
|
|
|
Velocity {
|
|
Velocity {
|
|
|
- v: Vec3::new(0.0, 0.0, 0.0),
|
|
|
|
|
|
|
+ v: Vec3::new(0., 0., 0.),
|
|
|
},
|
|
},
|
|
|
Rotation {
|
|
Rotation {
|
|
|
r: f32::to_radians(0.),
|
|
r: f32::to_radians(0.),
|
|
|
},
|
|
},
|
|
|
|
|
+ Thrust { t: 0. },
|
|
|
));
|
|
));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn apply_thrust(
|
|
fn apply_thrust(
|
|
|
time: Res<Time>,
|
|
time: Res<Time>,
|
|
|
- mut q: Query<(&mut Velocity, &mut Transform), With<Ship>>,
|
|
|
|
|
|
|
+ mut q: Query<(&mut Velocity, &mut Thrust, &mut Transform), With<Ship>>,
|
|
|
keyboard: Res<Input<KeyCode>>,
|
|
keyboard: Res<Input<KeyCode>>,
|
|
|
) {
|
|
) {
|
|
|
- let mut thrust = Vec3::ZERO;
|
|
|
|
|
- for (mut vel, mut trans) in &mut q {
|
|
|
|
|
|
|
+ for (mut vel, mut thr, mut trans) in &mut q {
|
|
|
for k in keyboard.get_pressed() {
|
|
for k in keyboard.get_pressed() {
|
|
|
- if k == &KeyCode::W {
|
|
|
|
|
- thrust = (trans.rotation * Vec3::Y) * MAIN_THRUST * time.delta_seconds();
|
|
|
|
|
|
|
+ match k {
|
|
|
|
|
+ KeyCode::ShiftLeft => thr.t += MAIN_THRUST * time.delta_seconds(),
|
|
|
|
|
+ KeyCode::ControlLeft => thr.t -= MAIN_THRUST * time.delta_seconds(),
|
|
|
|
|
+ KeyCode::X => thr.t = 0.,
|
|
|
|
|
+ _ => (),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- vel.v += thrust;
|
|
|
|
|
|
|
+ thr.t = thr.t.clamp(0., 100.);
|
|
|
|
|
+ vel.v += (trans.rotation * Vec3::Y) * thr.t;
|
|
|
trans.translation += vel.v;
|
|
trans.translation += vel.v;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|