From 2d12f5b3922aeb4e486f80deef06c459c2cd1294 Mon Sep 17 00:00:00 2001 From: Franklin Date: Thu, 23 Nov 2023 13:52:19 -0400 Subject: [PATCH] Weapon sway rot and translate when moving cursor --- Design.md | 2 +- assets/character/main_character.glb | Bin 49370400 -> 49370308 bytes assets/weapons/ak105_rifle.glb | Bin 8228460 -> 8228456 bytes .../markers/proxy/character/player_eye.rs | 9 +- src/comps/core/weapons/firearm.rs | 2 +- src/logic/core/guns/shoot.rs | 6 +- src/logic/core/player/camera_player_sync.rs | 86 ++++++++++++------ 7 files changed, 72 insertions(+), 33 deletions(-) diff --git a/Design.md b/Design.md index ed2b842..f125b3a 100644 --- a/Design.md +++ b/Design.md @@ -21,7 +21,7 @@ Multiplayer - [ ] Weapon Sway PENDING!!! - [x] Fixing leaning - [x] Snap back leaning too quick - - [ ] Issue with moving around quickly + - [x] Issue with moving around quickly - [ ] Bring Crouching back - [ ] Inspect animation (procedural) - [ ] Reload animation (procedural) diff --git a/assets/character/main_character.glb b/assets/character/main_character.glb index 500d9d5c87e3740d6ccba6deffdae02b16033c05..986337b3eeb1fe9783929846d722ed9ef1473503 100644 GIT binary patch delta 4627 zcmbW%Wpoqi9>;MgTHL+3la|aRlVosrcXxMpmjcBZ+}*vnOA8ctcXyWEWqp_Zeeb#F zzQ29({bbH0|2&yF^JL}b=!{XDqBAD%+@nFIpg3{jL^b#t6xfx#LAWz8Jbg&O^!eRh zw`sZDVTRlGnPwpHzjMyD0_nVl&!ZED-tgOYz;qd5w%-a^-hkiZv;3y%^SR70!|Su$ zZY$vT`aB-L?ZoY$$N3&!y{M_rm|ja`?l7XZ@t|v7W6sd2cLceNLMxv02mS1V{8vs;jcymfvUiT~6PK9L~y!EN;Kw@Y=TS zN5B&tsZyQ&%76^Y{aP%cm*J(zvs#zu(Cvw|YRQSKw95iQ#*Rr(}v^h+lE7S_JwJF?& zY53iiX?ndKLk)}5emx3y!0oY2ea^6)TTAjfBb}^Syp}eI?eSaoe|D+qvAw1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cHiC&VBHQlTCgV1flUIN*W@ zJ_Ha#eP{p;p%L5#cSB=n0!^VAG=~<@67GRk&>HTAG`J7$hc?g_9)Nbx9y&lr=meeN zLFfWq;UVY--Qi*A0X?A?^oBn02s{eu@EG)k$DtqehXF7U2Eky+fG1!G425AZ97e#C zFcO}EQSda3hA}V}o`G@jEIbF}VFFBqNstLyFd3#mHsrum$c1Sz9cI8xm<18chUei0 zm;-ZR9?XXq;U#z(7Qid85Ej8=comkwQdkDdVFj#&Rqz_T4y$1etc5pV9lQzaVFPT0 zw_p=&hApra-iCMJUDyVB@E&Z39k3JfVHfO%Jx~De!(R9R_Q8Jm5DvgWI0T2`BlsAO zz$b7Nj=^y_0Vm-Ud4Ld-wr< zgrDGN_yvB2-{5!n1O9}+;2QiLr|mCZZ{i>xib65C4ica^Tn~wG1C)Rpp(K=o(ohD< z!c9;P%0mUH2$i5RRDqkJD%=9MLK0MiWT*}`peEb~x5FJ!3u;3hs0(*O3{oH!>VW|! zSYU$#E_mQW03p0?tF3=Sof^N_q9)=#!6M8{!=mU?yqmT}dL0@(1Uv~N;VBpePs3;!17qPC7zfY7b1)tzz(kk?nUDpOVG3kJ4ornym*e0ULFf|p?dyaEeh5iEvRVF@gSWw0Dpz)DyJufglE8rHyCcmvkK zo3I`>z(#lrHo<1t0$bs2cn98vZIB1=!FJdIJ0Tx-!EV?C1@J!Xg%4mK?1vBG033uv za2P&0!QH(9ETHd5>COVa2h^?&*2L=183nJoQDhWC42>6!$tT8F2QBE0$1bn KwEe}8>i-YC2F$Sl diff --git a/assets/weapons/ak105_rifle.glb b/assets/weapons/ak105_rifle.glb index bae8dfece685d84ff63691391b63173417a77a8f..2266a2f3cb06fa9375fa102e3d9dd797863a3723 100644 GIT binary patch delta 715 zcmZwB$x{Z&^2YIG0`3BF0SyGiBuW%el(^*Nfm<%Q z${%5I;9v6K(eh~dovY=0^|`$6->diY+waH^#LLxu&I*M>l}0^O{2n*ffG4Dvl}5Ra z(vF)JLEBj=73FfhYr+9_}7O{jPma&58Sj7vJP(}qW@d|6G;x*o29UIuhTfD;--s1zd SQNu@k!e@Nhuchk0R{sKuYU2$6 delta 721 zcmZwBxmOcG0LSrl5s)L^;4Lu$bT!18ot@bkyirjQQ4vrY|JJP{HCr0(_dU-meX4rJ?{Rllv2!KUFp_Oar_-y&s@FF#>?MDK zj^uOD`mq)))q)N1QHPDFM*|wM2~B853tExFW^BP$Y{Pc!z)rNG9lNj_d$1S#upb9- z5FJS45HiT36J6-WVI0BQ$D=rg9D0z)aR^9+P>7&m5W~Wu7bkEMr*Il)a2Ds#hx53A zi|EHCT*d$faRo!TieX&Cb=<%RZekQ;7{@K##vM#x5_d6$d$^Bj6z~8KQN$z6U>1)t mhbMT75}u)qc|6ApEMO58yu>TK#v8oFJG{q-AGM(Rv-l4MO8{vA diff --git a/src/comps/core/markers/proxy/character/player_eye.rs b/src/comps/core/markers/proxy/character/player_eye.rs index 9e6a81f..83f8cb3 100644 --- a/src/comps/core/markers/proxy/character/player_eye.rs +++ b/src/comps/core/markers/proxy/character/player_eye.rs @@ -3,7 +3,7 @@ use bevy_rapier3d::prelude::*; use crate::{comps::core::markers::{proxy::physics::rapier::LinkToPlayer, camera::MainCamera}, logic::core::player::player_values_state::PlayerValuesState}; -use super::third_person_camera::{ThirdPersonCameraProxy, ThirdPersonCamera}; +use super::{third_person_camera::{ThirdPersonCameraProxy, ThirdPersonCamera}, in_player_hands_parent::InPlayerHandsParent}; #[derive(Component, Reflect, Default, Debug)] @@ -15,6 +15,7 @@ pub fn insert_components_into_spawned_player( eye_query: Query>, third_person_camera_query: Query>, player_collider_query: Query, With, Added)>, + mut hand_query: Query<(Entity, &mut Transform), (With, Without, Without)>, player_values_state: Res, ) { for eye in eye_query.iter() { @@ -22,7 +23,7 @@ pub fn insert_components_into_spawned_player( let camera = commands .spawn(MainCamera) .insert(Camera3dBundle { - transform: Transform::from_xyz(0.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(0.0, 0.0, 0.0), ..Default::default() }) //s.insert(Skybox(skybox_handle.clone())) @@ -32,6 +33,10 @@ pub fn insert_components_into_spawned_player( }) //.push_children(&[player_hand]) .id(); + for (hand, mut hand_transform) in hand_query.iter_mut() { + hand_transform.rotate_y(180.0f32.to_radians()); + commands.entity(hand).set_parent(camera); + } commands.entity(eye).add_child(camera); } for third_person_camera in third_person_camera_query.iter() { diff --git a/src/comps/core/weapons/firearm.rs b/src/comps/core/weapons/firearm.rs index 62dafaa..c446137 100644 --- a/src/comps/core/weapons/firearm.rs +++ b/src/comps/core/weapons/firearm.rs @@ -111,7 +111,7 @@ impl Firearm { }, final_aimed_rotation: Quat::default(), rotation_offset: Quat::default(), - final_aimed_position: Vec3 { x: 0.016, y: 0.0, z: -0.1 }, + final_aimed_position: Vec3 { x: 0.025, y: 0.003, z: -0.1 }, translation_offset: Vec3 { x: -0.2, y: -0.03, z: 0.0 }, scale_factor: 0.2, firearm_type: FirearmType::Primary, diff --git a/src/logic/core/guns/shoot.rs b/src/logic/core/guns/shoot.rs index ba54c5f..96db312 100644 --- a/src/logic/core/guns/shoot.rs +++ b/src/logic/core/guns/shoot.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bevy::prelude::*; +use bevy::{prelude::*, render::render_resource::PrimitiveTopology}; use bevy_rapier3d::prelude::*; use crate::comps::core::{markers::{bullet::BulletMarker, muzzle_flash::MuzzleFlashMarker}, weapons::caliber::Caliber}; @@ -37,7 +37,7 @@ pub fn shoot_bullet( MuzzleFlashMarker(Timer::new(Duration::from_millis(10), TimerMode::Once)), )); // Spawn Line - /*commands.spawn( + commands.spawn( MaterialMeshBundle { mesh: { let mut mesh = Mesh::new(PrimitiveTopology::LineStrip); @@ -52,7 +52,7 @@ pub fn shoot_bullet( transform: firing_point, ..Default::default() } - );*/ + ); spawn_bullet( commands, diff --git a/src/logic/core/player/camera_player_sync.rs b/src/logic/core/player/camera_player_sync.rs index 08f642b..57d4d02 100644 --- a/src/logic/core/player/camera_player_sync.rs +++ b/src/logic/core/player/camera_player_sync.rs @@ -1,8 +1,8 @@ -use bevy::{input::mouse::MouseMotion, prelude::*, window::CursorGrabMode}; +use bevy::{input::mouse::MouseMotion, prelude::*, window::CursorGrabMode, ecs::system::SystemParam}; //use bevy_rapier3d::prelude::*; use crate::{ - comps::core::markers::{camera::MainCamera, player::Player, proxy::{physics::utils::F32Ext, character::player_character::PlayerCharacter}}, + comps::core::markers::{camera::MainCamera, player::Player, proxy::character::{player_character::PlayerCharacter, player_eye::PlayerEye}, holdable::InPlayerHands}, ui::game::game_ui_state::{GameUiState, GameUiWindow}, }; @@ -29,8 +29,8 @@ impl Default for MouseMovementSettings { /// Synchronizes camera's translation to player. pub fn update_camera_vertical_position( - mut player: Query<(&mut Transform, &PlayerLinearXZState), (With, Without)>, - mut camera: Query<&mut Transform, (With, Without)>, + mut player: Query<(&mut Transform, &PlayerLinearXZState), (With, Without)>, + mut camera: Query<&mut Transform, (With, Without)>, time: Res