custom Sight glass for each optic. Done

This commit is contained in:
Franklin 2023-11-29 07:56:01 -04:00
parent 4337b9af15
commit 837ea1ab40
5 changed files with 40 additions and 12 deletions

View File

@ -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

Binary file not shown.

View File

@ -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::<physics::rapier::RigidBodyBlender>();
app.register_type::<physics::rapier::LinkToPlayer>();
// Debug for creating materials
app.register_type::<DebugMaterialResource>();
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);

View File

@ -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<Entity, Added<OpticSightGlass>>,
marker_query: Query<(Entity, &OpticSightGlass), Added<OpticSightGlass>>,
materials_query: Query<(&Parent, &Handle<StandardMaterial>), With<Handle<Mesh>>>,
mut materials: ResMut<Assets<StandardMaterial>>,
debug_mat: Res<DebugMaterialResource>
) {
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();
}
}
}

View File

@ -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 {