From e16a650b221d143d5735b2b9b28729c5ba395ef2 Mon Sep 17 00:00:00 2001 From: yuni Date: Sat, 8 Jun 2024 04:17:28 +0200 Subject: [PATCH] apply gravity towards Jupiter for objects orbiting Jupiter --- src/actor.rs | 34 ++++++++++++++++++++++++++++++++++ src/cmd.rs | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/src/actor.rs b/src/actor.rs index 7baef30..ed94544 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -44,6 +44,7 @@ impl Plugin for ActorPlugin { app.add_systems( Update, ( + handle_gravity, handle_input.run_if(in_control), handle_collisions, handle_damage, @@ -51,9 +52,16 @@ impl Plugin for ActorPlugin { ); app.add_systems(PostUpdate, (handle_vehicle_enter_exit,)); app.add_event::(); + app.insert_resource(GravityUpdateTimer(Timer::from_seconds( + 1.0, + TimerMode::Repeating, + ))); } } +#[derive(Resource)] +pub struct GravityUpdateTimer(Timer); + #[derive(Copy, Clone)] pub enum DamageType { Unknown, @@ -157,6 +165,8 @@ pub struct WantsMaxVelocity(pub f64); pub struct WantsToLookAt(pub String); #[derive(Component)] pub struct Identifier(pub String); +#[derive(Component)] +pub struct OrbitsJupiter; #[derive(Component)] pub struct LifeForm { @@ -632,3 +642,27 @@ fn handle_gforce( } } } + +fn handle_gravity( + time: Res