From 45c16b8612e3b34e0617385834a00138bfff45cd Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Sun, 26 Nov 2023 19:26:44 -0600 Subject: [PATCH] earth scale and spawning position improved along with part rotation sent to clients --- server/src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 289bec72167d5b60389077b2b8069b628e30fe84..f2437696f1615b9205464a563f169a6f2028623e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -13,6 +13,7 @@ pub mod packet; pub mod macros; const SCALE: f32 = 10.0; +const EARTH_SIZE: f32 = 1000.0; fn main() { let subscriber = tracing_subscriber::FmtSubscriber::new(); @@ -44,13 +45,12 @@ fn main() { fn spawn_planets(mut commands: Commands) { info!("Spawning planets"); let earth_pos = Transform::from_xyz(0.0, 0.0, 0.0); - let earth_radius = 2000.0 / SCALE; commands .spawn(PlanetBundle { planet_type: PlanetType::Earth, transform: TransformBundle::from(earth_pos), }) - .insert(Collider::ball(earth_radius)) + .insert(Collider::ball(EARTH_SIZE / SCALE)) .insert(RigidBody::Fixed); } @@ -80,7 +80,7 @@ fn on_message( let mut rng = rand::thread_rng(); rng.gen::() * std::f32::consts::PI * 2. }; - let mut transform = Transform::from_xyz(angle.cos() * 2050. / SCALE, angle.sin() * 2050. / SCALE, 0.0); + let mut transform = Transform::from_xyz(angle.cos() * 1100. / SCALE, angle.sin() * 1100. / SCALE, 0.0); transform.rotate_z(angle); let id = commands .spawn(PlayerBundle { @@ -102,7 +102,7 @@ fn on_message( planet_type: *planet_type, transform: proto_transform!(Transform::from_translation(translation * SCALE)), radius: match *planet_type { - PlanetType::Earth => 2000.0 + PlanetType::Earth => EARTH_SIZE } })); } @@ -139,7 +139,7 @@ fn on_message( } parts.push((id, Part { part_type: PartType::Hearty, - transform: proto_transform!(Transform::from_translation(transform.translation * SCALE)), + transform: proto_transform!(Transform::from_translation(transform.translation * SCALE).with_rotation(transform.rotation)), })); let packet = Packet::PartPositions { parts @@ -198,7 +198,7 @@ fn on_position_change( let id = commands.entity(entity).id().index(); updated_parts.push((id, Part { part_type: *part_type, - transform: proto_transform!(Transform::from_translation(transform.translation * SCALE)), + transform: proto_transform!(Transform::from_translation(transform.translation * SCALE).with_rotation(transform.rotation)), })); } @@ -216,7 +216,7 @@ fn on_position_change( planet_type: *planet_type, transform: proto_transform!(Transform::from_translation(transform.translation * SCALE)), radius: match *planet_type { - PlanetType::Earth => 2000.0, + PlanetType::Earth => EARTH_SIZE, } })); }