From 03ef6f7a1294f9e487626b5599249e59413942c9 Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Sat, 13 May 2023 08:02:19 -0400 Subject: [PATCH] joint bug "hot"fix --- server/src/handler.rs | 6 ++++-- server/src/manager.rs | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/server/src/handler.rs b/server/src/handler.rs index 75244fdae9eabe5f3a68cafdfe499de989e46c83..9eb43ca92e6ea90a073b24a8c43b4bb0f97b3908 100644 --- a/server/src/handler.rs +++ b/server/src/handler.rs @@ -270,6 +270,10 @@ pub async fn handle_client( e_write_handle .entities .insert(player_id, Entity::Player(player)); + + data_handle.rigid_body_set = rigid_body_set; + data_handle.collider_set = collider_set; + AttachedModule::attach_new( &mut data_handle, &mut e_write_handle, @@ -288,8 +292,6 @@ pub async fn handle_client( 0, angle, ); - data_handle.rigid_body_set = rigid_body_set; - data_handle.collider_set = collider_set; debug!("running"); } } diff --git a/server/src/manager.rs b/server/src/manager.rs index c7f29ee7b760f7c4294a8e00c0e97b176d548b76..5703b9f4821b09f4e2e6ea248ffbb56449246053 100644 --- a/server/src/manager.rs +++ b/server/src/manager.rs @@ -1,6 +1,6 @@ use async_std::channel::Sender; use async_std::sync::RwLock; -use nalgebra::point; +use nalgebra::{point, vector}; use rapier2d_f64::na::Vector2; use rapier2d_f64::prelude::{ BroadPhase, CCDSolver, ColliderBuilder, ColliderSet, FixedJointBuilder, ImpulseJointHandle, @@ -184,12 +184,23 @@ impl AttachedModule { panic!("unexpected parent"); } }; + + let parent_body = data.rigid_body_set.get(parent_handle).expect("Parent body does not exist"); + let parent_pos = vector![parent_body.translation().x, parent_body.translation().y]; + + let anchor = point![ + -0. / SCALE * rotation.cos() + 100. / SCALE * rotation.sin(), + -0. / SCALE * rotation.sin() - 100. / SCALE * rotation.cos() + ]; + + let module_pos = parent_pos + vector![anchor.x, anchor.y]; + // create attachment module let module_collider = ColliderBuilder::cuboid(25.0 / SCALE, 25.0 / SCALE) .mass_properties(module.mass_properties) .build(); let module_body = RigidBodyBuilder::dynamic() - .translation(module.translation) + .translation(module_pos) .rotation(module.heading) .build(); let attached_handle = data.rigid_body_set.insert(module_body); @@ -198,10 +209,7 @@ impl AttachedModule { attached_handle, &mut data.rigid_body_set, ); - let anchor = point![ - -0. / SCALE * rotation.cos() + 100. / SCALE * rotation.sin(), - -0. / SCALE * rotation.sin() - 100. / SCALE * rotation.cos() - ]; + let attach_joint = FixedJointBuilder::new() .local_anchor1(anchor) .local_anchor2(point![0.0, 0.0 / SCALE])