All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly

This commit is contained in:
Franklin 2023-11-25 14:49:57 -04:00
parent f78d4c7f40
commit c1cd45192d
4 changed files with 30 additions and 24 deletions

View File

@ -34,9 +34,9 @@ Multiplayer
- [x] EventCollision system that takes into account more than one type of collider.
- [x] Auto Low ready when gun collider hits object OR when player starts sprinting
- [ ] (Not a priority) Collision with wall and attempting to Aim can look very twitchy, maybe add a cooldown of 0.1-0.4s on each change from low ready to high ready
- [ ] Optics
- [ ] All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly
- [ ] Find some way to implement a shader for the optics
- [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
- [ ] Bobbing
- [ ] Gun Bob on run
- [ ] Gun Bob on walk

View File

@ -1,4 +1,4 @@
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}};
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}, math::Vec3};
use super::attachment::Attachment;
@ -10,6 +10,14 @@ pub enum Optic {
AimpointT1,
}
impl Optic {
pub fn aimed_in_gun_pos_offset(&self) -> Vec3 {
match self {
Optic::AimpointT1 => Vec3 { x: 0.0, y: -0.05, z: 0.0 },
}
}
}
impl Attachment for Optic {
fn current_attachment_index(&self) -> u32 {
match self {
@ -21,3 +29,4 @@ impl Attachment for Optic {
Vec::from([Self::AimpointT1])
}
}

View File

@ -37,19 +37,15 @@ impl FirearmState {
}
}
}
}
/*
Some(add) => {
let add_by = if add { 1 } else { -1 };
match attachment_slot.attachment {
Some(attachment) => ,
None => { // This means there was no attachment there. pass -1 to the from_index() fn. It will return the last one
},
pub fn get_optic_offset(&self) -> Vec3 {
for attachment_slot in self.attachment_slots.iter() {
if attachment_slot.slot_type == WeaponSlot::SightSlot {
if let Some(WeaponAttachment::Optic(optic)) = &attachment_slot.attachment {
return optic.aimed_in_gun_pos_offset()
}
}
}
Vec3::ZERO
}
}
},
None => {
attachment_slot.attachment = None;
},
*/

View File

@ -196,8 +196,9 @@ pub fn capture_hand_usage(
firearm_data.rebound_time_seconds
}
};
if resources.mouse_buttons.pressed(MouseButton::Right)
&& !resources.game_ui_state.any_window() && !player_linear_xz_state.is_sprinting() && !player_firing_info.gun_colliding_with_object
if resources.mouse_buttons.pressed(MouseButton::Right) // Aiming in (RClick)
&& !resources.game_ui_state.any_window() && !player_linear_xz_state.is_sprinting()
&& !player_firing_info.gun_colliding_with_object
{
player_firing_info.gun_ready_pose = GunReadyPose::HighReady;
let rotation_lerp_quat = in_hand_transform.rotation.lerp(
@ -207,7 +208,7 @@ pub fn capture_hand_usage(
.clamp(0.0, 1.0),
);
let position_lerp_vec3 = in_hand_transform.translation.lerp(
firearm_data.final_aimed_position + resources.player_settings.pos_aimed_offset,
firearm_data.final_aimed_position + resources.player_settings.pos_aimed_offset + firearm_state.get_optic_offset(),
(resources.time.delta_seconds()
/ lerp_time)
.clamp(0.0, 1.0),
@ -230,7 +231,7 @@ pub fn capture_hand_usage(
}
// SHOOTING & RECOIL
if resources.mouse_buttons.pressed(MouseButton::Left)
if resources.mouse_buttons.pressed(MouseButton::Left) // Shooting (LClick)
&& !resources.game_ui_state.any_window() && player_firing_info.gun_ready_pose == GunReadyPose::HighReady
{
if let Some(magazine_data) = &mut firearm_state.magazine_data {