base handle_wants_maxvelocity
on current orbital velocity
This commit is contained in:
parent
76272a7fc2
commit
cd13b529c3
26
src/actor.rs
26
src/actor.rs
|
@ -31,7 +31,7 @@ impl Plugin for ActorPlugin {
|
|||
update_physics_lifeforms,
|
||||
update_power,
|
||||
handle_wants_maxrotation,
|
||||
handle_wants_maxvelocity,
|
||||
handle_wants_maxvelocity.run_if(any_with_component::<WantsMaxVelocity>),
|
||||
handle_wants_lookat.run_if(alive),
|
||||
),
|
||||
);
|
||||
|
@ -548,11 +548,29 @@ fn handle_wants_maxrotation(
|
|||
/// Slows down NPC's movement until they reach their target velocity.
|
||||
fn handle_wants_maxvelocity(
|
||||
time: Res<Time>,
|
||||
mut query: Query<(&mut LinearVelocity, &Engine, &WantsMaxVelocity)>,
|
||||
mut query: Query<(
|
||||
&Position,
|
||||
&mut LinearVelocity,
|
||||
&Engine,
|
||||
&WantsMaxVelocity,
|
||||
Option<&OrbitsJupiter>,
|
||||
)>,
|
||||
id2pos: Res<game::Id2Pos>,
|
||||
) {
|
||||
let dt = time.delta_seconds();
|
||||
for (mut v, engine, maxv) in &mut query {
|
||||
let target_velocity = DVec3::splat(0.0);
|
||||
let jupiter_pos: DVec3 = if let Some(jupiter_pos) = id2pos.0.get(cmd::ID_JUPITER) {
|
||||
*jupiter_pos
|
||||
} else {
|
||||
warn!("Could not determine Jupiter's position");
|
||||
DVec3::ZERO
|
||||
};
|
||||
for (pos, mut v, engine, maxv, orbits_jupiter) in &mut query {
|
||||
let target_velocity = if orbits_jupiter.is_some() {
|
||||
let relative_pos = pos.0 - jupiter_pos;
|
||||
nature::orbital_velocity(relative_pos, nature::JUPITER_MASS)
|
||||
} else {
|
||||
DVec3::ZERO
|
||||
};
|
||||
let relative_velocity = v.0 - target_velocity;
|
||||
let relative_speed = relative_velocity.length();
|
||||
|
||||
|
|
Loading…
Reference in a new issue