From 494e99a548ee56a557c9e9becd4ab0722da8f65c Mon Sep 17 00:00:00 2001 From: Franklin Date: Tue, 14 Nov 2023 16:22:54 -0400 Subject: [PATCH] Removed not needed system and added impulse force to dropped guns --- Readme.md | 15 ++++++++++++--- src/comps/core/items/item.rs | 5 +++++ src/comps/core/spawners/item.rs | 1 + src/comps/core/spawners/player.rs | 2 +- src/logic/core/player/hands.rs | 5 ++--- src/logic/core/player/inventory.rs | 22 ++++++++++++---------- src/scenes/scene1/init.rs | 4 ++-- src/scenes/scene1/items.rs | 16 ---------------- src/scenes/scene1/mod.rs | 1 - 9 files changed, 35 insertions(+), 36 deletions(-) delete mode 100644 src/scenes/scene1/items.rs diff --git a/Readme.md b/Readme.md index 7f82a08..37a8dc3 100644 --- a/Readme.md +++ b/Readme.md @@ -1,11 +1,18 @@ # Experimental game + ## Things to finish: +### - New Movement System +- [ ] Rotations and transforms are based on animations +- [ ] Camera is a child of the head +- [ ] Figure out how rotation up and down will work, maybe dividing upper and lower body animations +- [ ] Shuffling feet when rotating + - [ ] Perfect movement -- [x] Equipping items -- [x] Replace items in the same slot, drop them -- [ ] When equipping an item that replaces another item because of the slot, throw item towards front of player +- [x] ~~Equipping items~~ +- [x] ~~Replace items in the same slot, drop them~~ +- [x] When equipping an item that replaces another item because of the slot, throw item towards front of player with a specific impulse - [ ] Gun aiming and noscope is not the same position - [ ] Controls being bindable - [ ] Gun moving out of the way on a collision @@ -14,6 +21,8 @@ - [ ] Persistent magazine data - [ ] Perfectly center interact clue text on screen - [ ] Fix: No Sprinting while aiming +- [x] ~~FIX: Gun spawning way in front of player~~ +- [ ] Player is rotating on an axis that it shouldn't - [ ] Fix: Make gun have more priority in rendering. So it doesn't clip through walls diff --git a/src/comps/core/items/item.rs b/src/comps/core/items/item.rs index 310a7ab..125adeb 100644 --- a/src/comps/core/items/item.rs +++ b/src/comps/core/items/item.rs @@ -33,6 +33,7 @@ pub trait Item: Sync + Send { transform: Transform, assets_gltf: &GltfAssets, loaded_gltf_assets: &Assets, + with_impulse: Vec3, ) { match self.get_type() { ItemType::Holdable(object_type) => { @@ -89,6 +90,10 @@ pub trait Item: Sync + Send { firearm_size.y, firearm_size.z, ), + ExternalImpulse { + impulse: with_impulse, + ..Default::default() + }, Interactable::Item(firearm.get_item_arc()), )) .push_children(&[firearm_asset_entity]); diff --git a/src/comps/core/spawners/item.rs b/src/comps/core/spawners/item.rs index 56b5dae..8026b34 100644 --- a/src/comps/core/spawners/item.rs +++ b/src/comps/core/spawners/item.rs @@ -30,6 +30,7 @@ pub fn item_spawner( component_sp.get_transform(), &assets_gltf, &loaded_gltf_assets, + Vec3::ZERO, ) } //m4.spawn(&mut commands, item_sp.at, &assets_gltf, &loaded_gltf_assets); diff --git a/src/comps/core/spawners/player.rs b/src/comps/core/spawners/player.rs index 001898f..06e7ce3 100644 --- a/src/comps/core/spawners/player.rs +++ b/src/comps/core/spawners/player.rs @@ -51,7 +51,7 @@ pub fn player_spawner( let player_hand = commands .spawn((PlayerHand, Name::new("Player Hand"))) .insert(TransformBundle::from(Transform::from_xyz( - 0.6, -0.45, -20.0, + 0.6, -0.45, 0.0, ))) .insert(VisibilityBundle { visibility: Visibility::Inherited, diff --git a/src/logic/core/player/hands.rs b/src/logic/core/player/hands.rs index 408e4a5..eb0d031 100644 --- a/src/logic/core/player/hands.rs +++ b/src/logic/core/player/hands.rs @@ -5,16 +5,15 @@ use crate::{ comps::core::{ events::pickup_item::PickupItemEvent, inventory::player_inventory::PlayerInventory, - items::item::ItemType, markers::{ camera::MainCamera, firearm::{FirearmData, MagazineData}, - holdable::{HoldableObjectType, InPlayerHands}, + holdable::InPlayerHands, interactable::Interactable, player::{Player, PlayerHand}, }, }, - logic::core::guns::{firearm::Firearm, player_firing::PlayerFiringInfo, shoot::shoot_bullet}, + logic::core::guns::{player_firing::PlayerFiringInfo, shoot::shoot_bullet}, setup::{ animations::AllFirearmAnimations, equipment::{Equipment, EquipmentChangeEvent}, diff --git a/src/logic/core/player/inventory.rs b/src/logic/core/player/inventory.rs index 2b111ed..516ee81 100644 --- a/src/logic/core/player/inventory.rs +++ b/src/logic/core/player/inventory.rs @@ -29,6 +29,14 @@ pub fn update_player_inventory_system( .entity(event.entity) .despawn_descendants() .despawn(); + let drop_position = Transform::from_translation( + player_transform.translation + + player_transform.up() * 3.0 + + player_transform.forward() * 2.0, + ); + let drop_impulse = player_transform.translation + + player_transform.up() * 100.0 + + player_transform.forward() * 30.0; match firearm.firearm_data().firearm_type { FirearmType::Primary => { // Send equipment_changed_event @@ -36,13 +44,10 @@ pub fn update_player_inventory_system( // Drop this one primary_item.spawn( &mut commands, - Transform::from_translation( - player_transform.translation - + player_transform.up() * 5.0 - + player_transform.forward(), - ), + drop_position, &assets_gltf, &loaded_gltf_assets, + drop_impulse, ); player_inventory.primary.item = Some(firearm.get_item_box()) @@ -55,13 +60,10 @@ pub fn update_player_inventory_system( if let Some(secondary) = player_inventory.get_secondary() { secondary.spawn( &mut commands, - Transform::from_translation( - player_transform.translation - + player_transform.up() * 5.0 - + player_transform.forward(), - ), + drop_position, &assets_gltf, &loaded_gltf_assets, + drop_impulse, ); player_inventory.secondary.item = Some(firearm.get_item_box()) diff --git a/src/scenes/scene1/init.rs b/src/scenes/scene1/init.rs index ddf69fd..e4d2035 100644 --- a/src/scenes/scene1/init.rs +++ b/src/scenes/scene1/init.rs @@ -26,7 +26,7 @@ use crate::{ }; use super::{ - ground::spawn_ground, items::spawn_items, lighting::setup_lighting, obstacles::spawn_obstacles, + ground::spawn_ground, lighting::setup_lighting, obstacles::spawn_obstacles, skybox::set_skybox_if_loaded, spawn_points::set_spawn_points, }; @@ -43,7 +43,7 @@ pub fn load_scene(application: &mut App) { application.add_systems(Startup, spawn_ground); application.add_systems( Startup, - (spawn_obstacles, spawn_items.after(load_all_assets)), + spawn_obstacles, ); application.add_systems(Startup, setup_lighting); application.add_systems(Startup, set_spawn_points); diff --git a/src/scenes/scene1/items.rs b/src/scenes/scene1/items.rs deleted file mode 100644 index 44b1707..0000000 --- a/src/scenes/scene1/items.rs +++ /dev/null @@ -1,16 +0,0 @@ -use bevy::{gltf::Gltf, prelude::*}; - -use crate::{ - comps::core::items::{guns::m4a1::M4a1GunItem, item::Item}, - setup::assets::GltfAssets, -}; - -pub fn spawn_items( - mut commands: Commands, - assets_gltf: Res, - loaded_gltf_assets: Res>, -) { - let transform = Transform::from_xyz(20.0, 1.0, 10.0); - let m4item = M4a1GunItem; - m4item.spawn(&mut commands, transform, &assets_gltf, &loaded_gltf_assets); -} diff --git a/src/scenes/scene1/mod.rs b/src/scenes/scene1/mod.rs index 6cff438..9556a4f 100644 --- a/src/scenes/scene1/mod.rs +++ b/src/scenes/scene1/mod.rs @@ -1,7 +1,6 @@ pub mod init; pub mod ground; -pub mod items; pub mod lighting; pub mod obstacles; pub mod skybox;