Fixed firearm y_rot glitch. Now firing point is where it should be

This commit is contained in:
Franklin 2023-11-09 00:06:11 -04:00
parent a64e646e78
commit 47764f63a1
2 changed files with 20 additions and 12 deletions

View File

@ -15,8 +15,8 @@ impl Firearm {
Firearm::M4A1 => { Firearm::M4A1 => {
FirearmData { FirearmData {
firing_point: FiringPoint { firing_point: FiringPoint {
forward: 1.0, forward: 0.0,
up: 1.0, up: 0.0,
right: 0.0, right: 0.0,
}, },
caliber: Caliber::NATO556, caliber: Caliber::NATO556,

View File

@ -59,27 +59,35 @@ fn spawn_firearm_on_player_hands(
if let Some(gltf) = loaded_gltf_assets.get(&asset_handle.asset) { if let Some(gltf) = loaded_gltf_assets.get(&asset_handle.asset) {
let firearm_data: FirearmData = firearm.firearm_data(); let firearm_data: FirearmData = firearm.firearm_data();
let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0); 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.holdable_object_data().y_rot,
)); ));
firearm_transform.scale = firearm_transform.scale * firearm_data.scale_factor; firearm_transform.scale = firearm_transform.scale * firearm_data.scale_factor;
let scene = gltf.scenes[0].clone(); let scene = gltf.scenes[0].clone();
let firearm_asset_entity = commands.spawn((SceneBundle {
let firearm_entity = commands
.spawn((
SceneBundle {
scene, scene,
visibility: Visibility::Inherited, visibility: Visibility::Inherited,
transform: firearm_transform, transform: firearm_transform,
..default() ..default()
}, }, Name::new("Firearm Gltf Asset"))).id();
let firearm_entity = commands
.spawn((
firearm_data.clone(), firearm_data.clone(),
firearm.holdable_object_data(), firearm.holdable_object_data(),
MagazineData { rounds_shot: 0, max_capacity: firearm_data.max_capacity }, MagazineData { rounds_shot: 0, max_capacity: firearm_data.max_capacity },
InPlayerHands, 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(); .id();
commands.entity(player_hands).push_children(&[firearm_entity]); commands.entity(player_hands).push_children(&[firearm_entity]);