From 47764f63a117997aff47e715b44551b75f587d17 Mon Sep 17 00:00:00 2001 From: Franklin Date: Thu, 9 Nov 2023 00:06:11 -0400 Subject: [PATCH] Fixed firearm y_rot glitch. Now firing point is where it should be --- src/logic/core/guns/firearm.rs | 4 ++-- src/setup/equipment.rs | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/logic/core/guns/firearm.rs b/src/logic/core/guns/firearm.rs index d77d592..7863b92 100644 --- a/src/logic/core/guns/firearm.rs +++ b/src/logic/core/guns/firearm.rs @@ -15,8 +15,8 @@ impl Firearm { Firearm::M4A1 => { FirearmData { firing_point: FiringPoint { - forward: 1.0, - up: 1.0, + forward: 0.0, + up: 0.0, right: 0.0, }, caliber: Caliber::NATO556, diff --git a/src/setup/equipment.rs b/src/setup/equipment.rs index c7e51fe..dee7c66 100644 --- a/src/setup/equipment.rs +++ b/src/setup/equipment.rs @@ -59,27 +59,35 @@ fn spawn_firearm_on_player_hands( if let Some(gltf) = loaded_gltf_assets.get(&asset_handle.asset) { let firearm_data: FirearmData = firearm.firearm_data(); let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0); - firearm_transform.rotate_y(utils::rad_deg::radians_from_degrees( + + firearm_transform.rotate_local_y(utils::rad_deg::radians_from_degrees( firearm.holdable_object_data().y_rot, )); firearm_transform.scale = firearm_transform.scale * firearm_data.scale_factor; let scene = gltf.scenes[0].clone(); - + let firearm_asset_entity = commands.spawn((SceneBundle { + scene, + visibility: Visibility::Inherited, + transform: firearm_transform, + ..default() + }, Name::new("Firearm Gltf Asset"))).id(); let firearm_entity = commands .spawn(( - SceneBundle { - scene, - visibility: Visibility::Inherited, - transform: firearm_transform, - ..default() - }, firearm_data.clone(), firearm.holdable_object_data(), MagazineData { rounds_shot: 0, max_capacity: firearm_data.max_capacity }, InPlayerHands, - Name::new("Firearm") - )) + Name::new("Firearm"), + TransformBundle { + local: Transform::from_xyz(0.0, 0.0, 0.0), + ..Default::default() + }, + VisibilityBundle { + visibility: Visibility::Inherited, + ..Default::default() + } + )).push_children(&[firearm_asset_entity]) .id(); commands.entity(player_hands).push_children(&[firearm_entity]);