From 65c555aa0303e90e741301e44e565946b2968412 Mon Sep 17 00:00:00 2001 From: Franklin Blanco Date: Wed, 8 Nov 2023 13:17:45 -0800 Subject: [PATCH] Fixed player spawning without firearm bug --- src/logic/core/guns/shoot.rs | 2 +- src/logic/core/player/player_values_state.rs | 4 ++-- src/scenes/scene1/init.rs | 4 ++-- src/setup/equipment.rs | 1 + src/setup/spawn.rs | 4 ++-- src/ui/editor/inspector.rs | 12 ++++++++++++ src/ui/editor/plugin.rs | 5 +++-- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/logic/core/guns/shoot.rs b/src/logic/core/guns/shoot.rs index 99f9ddb..100af57 100644 --- a/src/logic/core/guns/shoot.rs +++ b/src/logic/core/guns/shoot.rs @@ -18,7 +18,7 @@ pub fn shoot_bullet( //252, 238, 128 color: Color::Rgba { red: 252., green: 238., blue: 128., alpha: 0.5 }, intensity: 0.005, - range: 30.0, + range: 50.0, shadows_enabled: true, ..Default::default() }, diff --git a/src/logic/core/player/player_values_state.rs b/src/logic/core/player/player_values_state.rs index a30d8a7..33c4f81 100644 --- a/src/logic/core/player/player_values_state.rs +++ b/src/logic/core/player/player_values_state.rs @@ -36,7 +36,7 @@ impl Default for PlayerValuesState { Self { max_linear_player_velocity: 20.0, player_acceleration: 20.0, - player_jump_force: 900.0, + player_jump_force: 1000.0, player_jump_cooldown_s: 0.075, player_sprint_speed_multiplier: 3.5, player_crouch_speed_multiplier: 0.25, @@ -47,7 +47,7 @@ impl Default for PlayerValuesState { player_crouch_height: 0.0, player_crouch_time_s: 1.25, player_linear_damping: 3.5, - player_linear_damping_while_jumping: 0.25, + player_linear_damping_while_jumping: 0.8, player_lean_time: 0.3, player_lean_angle: 30.0, player_lateral_acceleration_while_sprinting_multiplier: 0.2, diff --git a/src/scenes/scene1/init.rs b/src/scenes/scene1/init.rs index 19c9f61..cfc627f 100644 --- a/src/scenes/scene1/init.rs +++ b/src/scenes/scene1/init.rs @@ -8,7 +8,7 @@ use crate::{ }, hands::capture_hand_usage, player_vertical_sync::sync_player_y_state, player_values_state::PlayerValuesState, - }, guns::despawn_shots::despawn_muzzle_flashes}, setup::{assets::load_all_assets, load_state::GameLoadState, spawn::add_all_spawners, animations::{load_animations, AllFirearmAnimations}, equipment::{EquipmentChangeEvent, change_equipment}}, + }, guns::despawn_shots::despawn_muzzle_flashes}, setup::{assets::load_all_assets, load_state::GameLoadState, spawn::add_all_spawners, animations::{load_animations, AllFirearmAnimations}, equipment::{EquipmentChangeEvent, change_equipment}, spawners::player::player_spawner}, }; use super::{ @@ -38,7 +38,7 @@ pub fn load_scene(application: &mut App) { application.add_systems(Update, update_camera_vertical_position); application.add_systems(Update, capture_hand_usage); - application.add_systems(Update, change_equipment); + application.add_systems(Update, change_equipment.before(player_spawner)); application.add_systems(Update, despawn_muzzle_flashes); application.add_event::(); diff --git a/src/setup/equipment.rs b/src/setup/equipment.rs index 67126fc..c7e51fe 100644 --- a/src/setup/equipment.rs +++ b/src/setup/equipment.rs @@ -41,6 +41,7 @@ pub fn change_equipment( // Set the player's equipment to the newly spawned equipment player.0.equipment.primary_firearm = equipment_change_event.0.primary_firearm.clone(); + println!("Equipment change done"); } } diff --git a/src/setup/spawn.rs b/src/setup/spawn.rs index e04ed9f..8acf202 100644 --- a/src/setup/spawn.rs +++ b/src/setup/spawn.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -use super::spawners::{player::player_spawner, firearm::firearm_spawner}; +use super::{spawners::{player::player_spawner, firearm::firearm_spawner}, equipment::change_equipment}; /// Where some Bundle T will replace this. #[derive(Component, Reflect)] @@ -10,5 +10,5 @@ pub struct SpawnPoint { } pub fn add_all_spawners(application: &mut App) { - application.add_systems(Update, (player_spawner, firearm_spawner)); + application.add_systems(Update, (player_spawner, firearm_spawner).after(change_equipment)); } \ No newline at end of file diff --git a/src/ui/editor/inspector.rs b/src/ui/editor/inspector.rs index cba097b..5f8c2cd 100644 --- a/src/ui/editor/inspector.rs +++ b/src/ui/editor/inspector.rs @@ -21,6 +21,7 @@ pub fn inspector_ui(world: &mut World) { pub fn editor_controls() -> EditorControls { let mut editor_controls = EditorControls::default_bindings(); editor_controls.unbind(controls::Action::PlayPauseEditor); + editor_controls.insert( controls::Action::PlayPauseEditor, @@ -31,4 +32,15 @@ pub fn editor_controls() -> EditorControls { ); editor_controls +} + +pub fn set_cam3d_controls( + mut query: Query<&mut bevy_editor_pls::default_windows::cameras::camera_3d_free::FlycamControls>, +) { + let mut controls = query.single_mut(); + controls.key_forward = KeyCode::Up; + controls.key_back = KeyCode::Down; + controls.key_left = KeyCode::Left; + controls.key_right = KeyCode::Right; + controls.key_up = KeyCode::U; } \ No newline at end of file diff --git a/src/ui/editor/plugin.rs b/src/ui/editor/plugin.rs index fd40d1d..14c5fa7 100644 --- a/src/ui/editor/plugin.rs +++ b/src/ui/editor/plugin.rs @@ -4,7 +4,7 @@ use bevy_inspector_egui::bevy_egui::EguiPlugin; use crate::{logic::core::{guns::{player_firing::PlayerFiringInfo, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern}, player::{player_values_state::PlayerValuesState, camera_player_sync::MouseMovementSettings, player_movement::{PlayerLinearYState, PlayerLinearXZState, PlayerMovementInput}}}, comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::{HoldableObjectData, InPlayerHands}, player::{PlayerData, Player, PlayerHand}}, scenes::scene1::skybox::Cubemap, setup::{animations::{AllFirearmAnimations, FirearmAnimations}, assets::{GltfAssetType, GltfAssets}, equipment::Equipment, load_state::GameLoadState}}; -use super::inspector::editor_controls; +use super::inspector::{editor_controls, set_cam3d_controls}; //use super::inspector::inspector_ui; @@ -40,7 +40,8 @@ impl Plugin for MainEditorUiPlugin { .register_type::() .add_plugins(EguiPlugin) .add_plugins(EditorPlugin::default()) - .insert_resource(editor_controls()); + .insert_resource(editor_controls()) + .add_systems(Startup, set_cam3d_controls); //.add_plugins(ResourceInspectorPlugin::::default()); //.add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin) // adds default options and `InspectorEguiImpl`s //.add_systems(Update, inspector_ui);