From f910f4005b6fdf960bed7486d23cd49212b41141 Mon Sep 17 00:00:00 2001 From: Franklin Date: Sat, 25 Nov 2023 21:48:32 -0400 Subject: [PATCH] Fixed Gun dropping drops on only one side of player but impulse is not applied. Fix next --- Design.md | 3 ++- src/comps/core/inventory/player_inventory.rs | 12 +++++++++--- src/comps/core/items/guns/ak105.rs | 2 +- src/comps/core/markers/collider_flags.rs | 1 + src/comps/core/spawners/player.rs | 3 ++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Design.md b/Design.md index b392af6..9cb5392 100644 --- a/Design.md +++ b/Design.md @@ -49,7 +49,8 @@ Multiplayer - [ ] Real world magazines - [ ] Rewriting bullet physics to use raycasts & kinematic rigidbodies (logic controlled) - [x] Create a Controls struct that holds mappings to all the game keys and replace them in all the game's code - +- [x] Gun dropping drops on only one side of player +- [ ] TODO: Gun dropping does not apply impulse for some reason... # Design diff --git a/src/comps/core/inventory/player_inventory.rs b/src/comps/core/inventory/player_inventory.rs index b3237ed..f883f03 100644 --- a/src/comps/core/inventory/player_inventory.rs +++ b/src/comps/core/inventory/player_inventory.rs @@ -90,13 +90,19 @@ pub fn drop_slot_in_game_world( slot: PlayerInventorySlotType, item_state: Option, ) { - let drop_position = Transform::from_translation( + let mut drop_position = Transform::from_translation( player_transform.translation + player_transform.up() * 5.0 + + player_transform.forward() * 5.0 ); + drop_position.rotation = player_transform.rotation; + //drop_position.rotate_y(90.0f32.to_radians()); + drop_position.rotate_y(-90.0f32.to_radians()); + drop_position.rotate_x(45.0f32.to_radians()); + drop_position.rotate_z(45.0f32.to_radians()); let drop_impulse = player_transform.translation - + player_transform.up() * 100.0 - + player_transform.forward() * 30.0; + + (player_transform.up() * 1000000.0) + + (player_transform.forward() * 3000000.0); let item_inventory_slot = match slot { PlayerInventorySlotType::Primary => { diff --git a/src/comps/core/items/guns/ak105.rs b/src/comps/core/items/guns/ak105.rs index 416fcb7..c2e59c7 100644 --- a/src/comps/core/items/guns/ak105.rs +++ b/src/comps/core/items/guns/ak105.rs @@ -118,7 +118,7 @@ impl Item for Ak105GunItem { ..Default::default() }, RigidBody::Dynamic, - ColliderMassProperties::Mass(5.0), + ColliderMassProperties::Mass(0.1), GravityScale(4.0), ExternalImpulse { impulse: with_impulse, diff --git a/src/comps/core/markers/collider_flags.rs b/src/comps/core/markers/collider_flags.rs index 3a15ef5..49d3e18 100644 --- a/src/comps/core/markers/collider_flags.rs +++ b/src/comps/core/markers/collider_flags.rs @@ -10,6 +10,7 @@ bitflags! { const GUNS = 0b00000010; /// The value `C`, at bit position `2`. const SOLIDS = 0b00000100; + const PLAYER = 0b00001000; const ALL = u32::MAX; const NONE = 0; diff --git a/src/comps/core/spawners/player.rs b/src/comps/core/spawners/player.rs index 19b3d56..b053242 100644 --- a/src/comps/core/spawners/player.rs +++ b/src/comps/core/spawners/player.rs @@ -4,7 +4,7 @@ use bevy_rapier3d::prelude::*; use crate::{ comps::core::{ inventory::player_inventory::PlayerInventory, - markers::player::{Player, PlayerData}, + markers::{player::{Player, PlayerData}, collider_flags::ColliderFlags}, }, logic::core::{ guns::player_firing::PlayerFiringInfo, @@ -104,6 +104,7 @@ pub fn player_spawner( ..Default::default() }) // Data + .insert(CollisionGroups::new(Group::from_bits_retain(ColliderFlags::PLAYER.bits()), Group::from_bits_retain(ColliderFlags::SOLIDS.bits()))) .insert(PlayerFiringInfo::default()) .insert(PlayerInventory::default()) .add_child(player_scene);