diff --git a/Design.md b/Design.md index 28cd7ae..678cdba 100644 --- a/Design.md +++ b/Design.md @@ -37,9 +37,9 @@ Multiplayer - [x] Gun colliding with bullet, making it lower on every shot fired. - [x] Optics - [x] All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly - - [ ] TODO: Find some way to implement a shader for the optics (AFTER IMPLEMENTING NEW BULLET SYSTEM) - - [ ] Optic glass material - - [ ] Reticle render + - [x] Find some way to implement a shader for the optics (AFTER IMPLEMENTING NEW BULLET SYSTEM) + - [x] Optic glass material + - [ ] TODO: Reticle render - [ ] Parallax effect on reticle - [ ] Weapon Clipping - [x] Make the player's collider bigger towards the front @@ -56,7 +56,7 @@ Multiplayer - [x] Gun dropping does not apply impulse for some reason... - [x] Gun colliding with ground and going into low ready - [x] With introduction of floor collision groups now bullets go through floors -- [x] TODO: Huge bug all attachments get despawned and spawned when gun shoots +- [x] Huge bug all attachments get despawned and spawned when gun shoots # Design diff --git a/assets/attachments/aimpoint_t1.glb b/assets/attachments/aimpoint_t1.glb index 4e3173e..4e8d0b4 100644 Binary files a/assets/attachments/aimpoint_t1.glb and b/assets/attachments/aimpoint_t1.glb differ diff --git a/src/comps/core/markers/proxy/plugin.rs b/src/comps/core/markers/proxy/plugin.rs index 501a220..1fdb5ed 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, 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, gun_colliders::{GunFirearmCollider, update_gun_collider}, sight_placement::{SightPlacementStart, SightPlacementEnd}, optic_sight_glass::{OpticSightGlass, replace_optic_sight_material}}}; +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}, sight_placement::{SightPlacementStart, SightPlacementEnd}, optic_sight_glass::{OpticSightGlass, replace_optic_sight_material, DebugMaterialResource}}}; @@ -57,6 +57,10 @@ impl Plugin for ProxyComponentsPlugin { app.register_type::(); app.register_type::(); + // Debug for creating materials + app.register_type::(); + app.insert_resource(DebugMaterialResource::default()); + app.add_systems(Update, (physics_replace_proxies, update_game_load_state)); app.add_systems(Update, insert_components_into_spawned_player); app.add_systems(Update, insert_components_into_player_hand); diff --git a/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs b/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs index f942f49..a504188 100644 --- a/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs +++ b/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs @@ -1,21 +1,27 @@ use bevy::prelude::*; +use crate::comps::core::weapons::attachments::optic::Optic; + #[derive(Default, Component, Reflect, Debug)] #[reflect(Component)] -pub struct OpticSightGlass; +pub struct OpticSightGlass (pub Optic); + +#[derive(Default, Resource, Reflect, Debug)] +#[reflect(Resource)] +pub struct DebugMaterialResource(StandardMaterial); pub fn replace_optic_sight_material( //mut commands: Commands, - marker_query: Query>, + marker_query: Query<(Entity, &OpticSightGlass), Added>, materials_query: Query<(&Parent, &Handle), With>>, mut materials: ResMut>, + debug_mat: Res ) { - for marker in marker_query.iter() { - println!("One marker once"); + for (marker, optic_sight_glass) in marker_query.iter() { for (material_parent, material_handle) in materials_query.iter() { if marker == material_parent.get() { - if let Some(mut material) = materials.get_mut(material_handle) { - println!("Changed material"); + if let Some(material) = materials.get_mut(material_handle) { + *material = optic_sight_glass.0.sight_glass_material(); } } } diff --git a/src/comps/core/weapons/attachments/optic.rs b/src/comps/core/weapons/attachments/optic.rs index c9f2bf5..718c59b 100644 --- a/src/comps/core/weapons/attachments/optic.rs +++ b/src/comps/core/weapons/attachments/optic.rs @@ -1,4 +1,5 @@ -use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}, math::Vec3}; +use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}, math::Vec3, pbr::StandardMaterial, render::color::Color}; +use bevy_inspector_egui::egui::Rgba; use super::attachment::Attachment; @@ -16,6 +17,23 @@ impl Optic { Optic::AimpointT1 => Vec3 { x: 0.0, y: -0.05, z: 0.0 }, } } + pub fn sight_glass_material(&self) -> StandardMaterial { + match self { + Optic::AimpointT1 => { + StandardMaterial { + base_color: Color::Rgba { red: 0.0, green: 0.47, blue: 0.42, alpha: 0.48 }, + reflectance: 0.0, + diffuse_transmission: -2.0, + specular_transmission: -1.8, + thickness: 0.0, + ior: 0.0, + attenuation_distance: 1.0, + alpha_mode: bevy::pbr::AlphaMode::Blend, + ..Default::default() + } + }, + } + } } impl Attachment for Optic {