~starkingdoms/starkingdoms

03ef6f7a1294f9e487626b5599249e59413942c9 — c0repwn3r 2 years ago fe715d0
joint bug "hot"fix
2 files changed, 18 insertions(+), 8 deletions(-)

M server/src/handler.rs
M server/src/manager.rs
M server/src/handler.rs => server/src/handler.rs +4 -2
@@ 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");
                            }
                        }

M server/src/manager.rs => server/src/manager.rs +14 -6
@@ 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])