From d9af542d544c7eb6d8f3b93d9b89643e65cdfd4d Mon Sep 17 00:00:00 2001 From: yuni Date: Sat, 8 Jun 2024 04:17:54 +0200 Subject: [PATCH] give objects orbiting jupiter an orbital velocity on startup --- src/cmd.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cmd.rs b/src/cmd.rs index f7f6a3e..17e37e7 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -617,6 +617,12 @@ fn spawn_entities( settings: Res, ) { for state_wrapper in er_spawn.read() { + let jupiter_pos: DVec3 = if let Some(jupiter_pos) = id2pos.0.get(ID_JUPITER) { + *jupiter_pos + } else { + warn!("Could not determine Jupiter's position"); + DVec3::ZERO + }; let state = &state_wrapper.0; let mut rotation = state.rotation; if state.class == DefClass::Actor { @@ -669,6 +675,12 @@ fn spawn_entities( } * state.model_scale, ); let orbits_jupiter = state.id != ID_JUPITER; + let velocity = if orbits_jupiter { + let coords = absolute_pos - jupiter_pos; + state.velocity + nature::orbital_velocity(coords, nature::JUPITER_MASS) + } else { + state.velocity + }; // Spawn the actor let actor_entity; @@ -719,7 +731,7 @@ fn spawn_entities( // Physics Parameters if state.has_physics { actor.insert(RigidBody::Dynamic); - actor.insert(LinearVelocity(state.velocity)); + actor.insert(LinearVelocity(velocity)); actor.insert(AngularVelocity(state.angular_momentum)); actor.insert(ColliderDensity(state.density)); if state.collider_is_mesh {