From 0752435f9022ba035917491b60223b0ac6593cdb Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Sat, 12 Jul 2025 09:47:16 -0500 Subject: [PATCH] fix: attachment rotation --- crates/unified/assets/config/parts/housing.part.toml | 6 +++--- crates/unified/src/client/key_input.rs | 6 ++++-- crates/unified/src/server/player.rs | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/unified/assets/config/parts/housing.part.toml b/crates/unified/assets/config/parts/housing.part.toml index 498150f6453ee620a2df2110a5c7d99f218e6b68..5a732578e1f720fe5eacdfa78a8a5ab65705eed5 100644 --- a/crates/unified/assets/config/parts/housing.part.toml +++ b/crates/unified/assets/config/parts/housing.part.toml @@ -1,7 +1,7 @@ [part] name = "Housing" -sprite_connected = "textures/housing.png" -sprite_disconnected = "textures/housing.png" +sprite_connected = "textures/thruster_on.png" +sprite_disconnected = "textures/thruster_off.png" [physics] width = 50 @@ -27,4 +27,4 @@ snap = { translation = [ 0.0, -25.0, 0.0 ], rotation = 0.0 } [[joints]] id = "Left" target = { translation = [ -55.0, 0.0, 0.0 ], rotation = -270.0 } -snap = { translation = [ -25.0, 0.0, 0.0 ], rotation = 0.0 } \ No newline at end of file +snap = { translation = [ -25.0, 0.0, 0.0 ], rotation = 0.0 } diff --git a/crates/unified/src/client/key_input.rs b/crates/unified/src/client/key_input.rs index c9e570e0f85d4d017ad1da0d314f42b33d422b77..784e316ba07dfaaa8ce4de351f5e7e1160c1c9bd 100644 --- a/crates/unified/src/client/key_input.rs +++ b/crates/unified/src/client/key_input.rs @@ -1,8 +1,8 @@ use crate::attachment::{JointOf, Peer, SnapOf}; use crate::ecs::{Part, ThrustEvent}; -use bevy::color::palettes::css::{FUCHSIA, GREEN, WHITE}; +use bevy::color::palettes::css::{FUCHSIA, GREEN, ORANGE, WHITE}; use bevy::dev_tools::picking_debug::DebugPickingMode; -use bevy::math::Vec3Swizzles; +use bevy::math::{Vec3, Vec3Swizzles}; use bevy::prelude::{Gizmos, GlobalTransform, Query, ResMut, Resource, Transform, With}; use bevy::{ app::{App, Update}, @@ -91,6 +91,8 @@ fn draw_attachment_debug( if let Some(peer_id) = peer && let Ok(peer) = joints.get(peer_id.0) { let Ok(peer_parent_pos) = parts.get(peer.1.0) else { continue }; + gizmos.arrow_2d(peer_parent_pos.translation().xy(), peer_parent_pos.translation().xy() + + ((peer.0.rotation * peer_parent_pos.rotation()).mul_vec3(Vec3::Y).xy()*20.0), ORANGE); gizmos.arrow_2d(parent_pos.translation().xy(), peer_parent_pos.translation().xy(), WHITE); } } diff --git a/crates/unified/src/server/player.rs b/crates/unified/src/server/player.rs index b5780d1f965b6d0326a947100bb21693ca5fc336..9ae87685ec3341c349a25fddc366a737e30f7d85 100644 --- a/crates/unified/src/server/player.rs +++ b/crates/unified/src/server/player.rs @@ -108,13 +108,14 @@ fn dragging( // create the joint... let joint = FixedJointBuilder::new() .local_anchor1(target_joint.2.translation.xy()) - .local_basis2(0.0); + .local_basis1(target_joint.0.transform.rotation.to_euler(EulerRot::ZYX).0 + PI + - source_joint.0.transform.rotation.to_euler(EulerRot::ZYX).0); commands.entity(source_part.2) .insert(ImpulseJoint::new(target_part.2, joint)); teleport_to_translation = target_position.translation.xy(); - teleport_to_rotation = event.set_rotation; + teleport_to_rotation = target_position.rotation * source_joint.0.transform.rotation.inverse() * Quat::from_rotation_z(PI); new_vel = Some(*target_part.3); // and we're done! } else {