diff --git a/assets/weapons/ak105_rifle.glb b/assets/weapons/ak105_rifle.glb index 2605cd1..bae8dfe 100644 Binary files a/assets/weapons/ak105_rifle.glb and b/assets/weapons/ak105_rifle.glb differ diff --git a/src/comps/core/inventory/player_inventory.rs b/src/comps/core/inventory/player_inventory.rs index 5cf2cb0..b3237ed 100644 --- a/src/comps/core/inventory/player_inventory.rs +++ b/src/comps/core/inventory/player_inventory.rs @@ -92,8 +92,7 @@ pub fn drop_slot_in_game_world( ) { let drop_position = Transform::from_translation( player_transform.translation - + player_transform.up() * 3.0 - + player_transform.forward() * 2.0, + + player_transform.up() * 5.0 ); let drop_impulse = player_transform.translation + player_transform.up() * 100.0 diff --git a/src/comps/core/items/guns/ak105.rs b/src/comps/core/items/guns/ak105.rs index afebe0a..416fcb7 100644 --- a/src/comps/core/items/guns/ak105.rs +++ b/src/comps/core/items/guns/ak105.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use bevy::{prelude::*, gltf::Gltf}; use bevy_inspector_egui::egui::mutex::Mutex; -use bevy_rapier3d::{dynamics::{RigidBody, GravityScale, ExternalImpulse}, geometry::{ColliderMassProperties, Collider}}; +use bevy_rapier3d::{dynamics::{RigidBody, GravityScale, ExternalImpulse}, geometry::ColliderMassProperties}; use crate::{comps::core::{ grid::UGrid, @@ -105,7 +105,6 @@ impl Item for Ak105GunItem { if let Some(initial_attachments) = &self.initial_attachments { commands.entity(firearm_asset_entity).insert(initial_attachments.clone()); } - let firearm_size = firearm.get_size(); commands .spawn(( firearm.holdable_object_data(), @@ -121,11 +120,6 @@ impl Item for Ak105GunItem { RigidBody::Dynamic, ColliderMassProperties::Mass(5.0), GravityScale(4.0), - Collider::cuboid( - firearm_size.x, - firearm_size.y, - firearm_size.z, - ), ExternalImpulse { impulse: with_impulse, ..Default::default() diff --git a/src/comps/core/markers/proxy/plugin.rs b/src/comps/core/markers/proxy/plugin.rs index 69ada81..3e68354 100644 --- a/src/comps/core/markers/proxy/plugin.rs +++ b/src/comps/core/markers/proxy/plugin.rs @@ -2,7 +2,7 @@ use bevy::app::{Plugin, Update}; use crate::{setup::load_state::update_game_load_state, comps::core::weapons::{firearm::Firearm, attachments::{weapon_attachment::WeaponAttachment, optic::Optic, stock::Stock, compensator::Compensator, magazine::Magazine, foregrip::ForeGrip}, parts::{charging_handle::ChargingHandle, fire_selector::FireSelector, firing_point::FiringPoint, trigger::Trigger}, slot::{compensator_slot::CompensatorSlot, fore_grip_slot::ForeGripSlot, magazine_slot::MagazineSlot, sight_placement_start_slot::SightPlacementStartSlot, sight_placement_end_slot::SightPlacementEndSlot, stock_slot::StockSlot, utility_slot::UtilitySlot, slot::WeaponSlot}}}; -use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::{PlayerEye, insert_components_into_spawned_player}, in_player_hands_parent::{InPlayerHandsParent, insert_components_into_player_hand}, third_person_camera::ThirdPersonCameraProxy}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}, weapons::firearm::insert_firearm_state_to_firearms}; +use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::{PlayerEye, insert_components_into_spawned_player}, in_player_hands_parent::{InPlayerHandsParent, insert_components_into_player_hand}, third_person_camera::ThirdPersonCameraProxy}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}, weapons::{firearm::insert_firearm_state_to_firearms, gun_colliders::{GunFirearmCollider, update_gun_collider}}}; @@ -22,6 +22,7 @@ impl Plugin for ProxyComponentsPlugin { // Firearms app.register_type::(); + app.register_type::(); // Attachments app.register_type::(); @@ -56,5 +57,6 @@ impl Plugin for ProxyComponentsPlugin { app.add_systems(Update, insert_components_into_spawned_player); app.add_systems(Update, insert_components_into_player_hand); app.add_systems(Update, insert_firearm_state_to_firearms); + app.add_systems(Update, update_gun_collider); } } \ No newline at end of file diff --git a/src/comps/core/markers/proxy/weapons/firearm.rs b/src/comps/core/markers/proxy/weapons/firearm.rs index e548a2a..6acada6 100644 --- a/src/comps/core/markers/proxy/weapons/firearm.rs +++ b/src/comps/core/markers/proxy/weapons/firearm.rs @@ -12,7 +12,6 @@ pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> { attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>, in_player_hands_query: Query<'w, 's, &'static ItemId, With>, player_inventories_query: Query<'w, 's, &'static PlayerInventory>, - } /// This query inserts FirearmState into firearms, updates firearm assets that already have a FirearmState, diff --git a/src/comps/core/markers/proxy/weapons/gun_colliders.rs b/src/comps/core/markers/proxy/weapons/gun_colliders.rs new file mode 100644 index 0000000..4d281ca --- /dev/null +++ b/src/comps/core/markers/proxy/weapons/gun_colliders.rs @@ -0,0 +1,37 @@ +use bevy::prelude::*; +use bevy_rapier3d::geometry::Sensor; + +use crate::{comps::core::markers::holdable::InPlayerHands, utils::hierarchy::find_child_in_parent_children}; + + +/// This marker is to find the gun's collider that should be a sensor when equipped and a non-sensor when on the ground +#[derive(Component, Clone, Reflect, Default, Debug)] +#[reflect(Component)] +pub struct GunFirearmCollider; + + +/*for (gun_firearm_collider_entity, _) in gun_firearm_collider_query.iter() { + println!("a"); + if find_child_in_parent_children(commands, firearm_asset_entity, gun_firearm_collider_entity, &children) { + println!("Sensor"); + commands.entity(gun_firearm_collider_entity).insert(Sensor); + } + } */ +pub fn update_gun_collider( + mut commands: Commands, + gun_firearm_collider_query: Query>, + in_player_hands_query: Query>, + children: Query<&Children>, +) { + for gun_firearm_collider_entity in gun_firearm_collider_query.iter() { + let mut found = false; + for in_player_hands_entity in in_player_hands_query.iter() { + if find_child_in_parent_children(&mut commands, in_player_hands_entity, gun_firearm_collider_entity, &children) { + commands.entity(gun_firearm_collider_entity).insert(Sensor); + found = true; + } + } + if found { continue; } + commands.entity(gun_firearm_collider_entity).remove::(); + } +} \ No newline at end of file diff --git a/src/comps/core/markers/proxy/weapons/mod.rs b/src/comps/core/markers/proxy/weapons/mod.rs index 77a0ef8..0658ba3 100644 --- a/src/comps/core/markers/proxy/weapons/mod.rs +++ b/src/comps/core/markers/proxy/weapons/mod.rs @@ -1,2 +1,3 @@ pub mod firearm; -pub mod initial_attachments; \ No newline at end of file +pub mod initial_attachments; +pub mod gun_colliders; \ No newline at end of file diff --git a/src/comps/core/weapons/attachments/attachment.rs b/src/comps/core/weapons/attachments/attachment.rs new file mode 100644 index 0000000..1094c61 --- /dev/null +++ b/src/comps/core/weapons/attachments/attachment.rs @@ -0,0 +1,9 @@ + + +/// Trait that will contain all the SHARED properties in between all attachments +/// - Recoil reduction Vert and Horizontal +/// - Aim Speed +/// - +pub trait Attachment { + +} \ No newline at end of file diff --git a/src/comps/core/weapons/attachments/mod.rs b/src/comps/core/weapons/attachments/mod.rs index bb061dc..411b921 100644 --- a/src/comps/core/weapons/attachments/mod.rs +++ b/src/comps/core/weapons/attachments/mod.rs @@ -3,4 +3,6 @@ pub mod optic; pub mod magazine; pub mod compensator; pub mod stock; -pub mod foregrip; \ No newline at end of file +pub mod foregrip; +pub mod silencer; +pub mod attachment; \ No newline at end of file diff --git a/src/comps/core/weapons/attachments/silencer.rs b/src/comps/core/weapons/attachments/silencer.rs new file mode 100644 index 0000000..6a46a4a --- /dev/null +++ b/src/comps/core/weapons/attachments/silencer.rs @@ -0,0 +1,9 @@ +use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}}; + + +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)] +#[reflect(Component, Default)] +pub enum Silencer { + #[default] + FirstSilencer +} \ No newline at end of file diff --git a/src/logic/core/guns/despawn_shots.rs b/src/logic/core/guns/despawn_shots.rs index 1d82b04..f4b5a19 100644 --- a/src/logic/core/guns/despawn_shots.rs +++ b/src/logic/core/guns/despawn_shots.rs @@ -1,6 +1,6 @@ use crate::comps::core::markers::{bullet::BulletMarker, muzzle_flash::MuzzleFlashMarker}; use bevy::prelude::*; -use bevy_rapier3d::prelude::*; +use bevy_rapier3d::{prelude::*, rapier::geometry::CollisionEventFlags}; pub fn despawn_muzzle_flashes( mut commands: Commands, @@ -20,6 +20,7 @@ pub fn despawn_stray_bullets( mut meshes: ResMut>, mut materials: ResMut>, mut query: Query<(&mut BulletMarker, Entity, &Transform)>, + mut collisions: EventReader, //res: Res, time: Res