diff --git a/.vscode/settings.json b/.vscode/settings.json index c07dd5c..ab4fd48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,9 @@ { "rust-analyzer.debug.engine": "vadimcn.vscode-lldb", + "cSpell.words": [ + "Gamepad", + "qeury", + "Substep", + "xpbd" + ], } \ No newline at end of file diff --git a/README.md b/README.md index 8dd1c72..9b8c9a7 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,24 @@ The name is a bit confusing/misleading , so I am open for alternative names. [SECTION STILL BEING WORKED ON] #### Nix +Enter the directory project directory and run `nix-shell` command and then you can use cargo as per usual`cargo run`, or use `nix-shell --run "cargo run"` if you don't want to enter the shell. -Enter the directory project directory and run `nix-shell` command, or use `nix-shell --run "cargo run"` if you don't want to enter the shell. +#### Ubuntu +Fist you need to install rust, follow the instructions on the official rust lang website: +https://www.rust-lang.org/tools/install + +Next, you need following packages: +- `pkg-config` +- `libx11-dev` +- `libasound2-dev` +- `libudev-dev` + +you can get them via `apt` +```bash +apt-get update; apt-get install --no-install-recommends -y libasound2-dev libudev-dev libwayland-dev +``` + +now you should be good to go, and can run `cargo run` to build the project ### Building: diff --git a/src/lib.rs b/src/lib.rs index ae4d298..c3c85e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,9 +23,12 @@ use bevy::prelude::*; use bevy_editor_pls::prelude::*; use bevy_xpbd_3d::prelude::*; -use character_controller::*; -use input_processor::*; -use player_look::*; +mod weapon_framework; +mod player_utils; + +use player_utils::character_controller::*; +use player_utils::input_processor::*; +use player_utils::player_look::*; #[derive(Resource, Default, Debug)] struct IsMapSpawned(bool); diff --git a/src/player_utils.rs b/src/player_utils.rs index 15b96f9..b0a88d3 100644 --- a/src/player_utils.rs +++ b/src/player_utils.rs @@ -1,3 +1,3 @@ -mod character_controller; -mod input_processor; -mod player_look; \ No newline at end of file +pub mod character_controller; +pub mod input_processor; +pub mod player_look; \ No newline at end of file diff --git a/src/player_utils/character_controller.rs b/src/player_utils/character_controller.rs index 74417ff..2907027 100644 --- a/src/player_utils/character_controller.rs +++ b/src/player_utils/character_controller.rs @@ -15,8 +15,21 @@ You should have received a copy of the GNU General Public License 3.0 along with this program. If not, see . */ -use crate::{input_processor::*, player_look::*}; -use bevy::prelude::*; +use crate::player_utils::{input_processor::*, player_look::*}; +use bevy::{ + prelude::*, + math::Vec3, + time::Time, + ecs::{ + event::EventReader, + system::*, + query::*, + }, + transform::components::Transform, + core_pipeline::core_3d::Camera3d, + gizmos::gizmos::Gizmos, + +}; use bevy_xpbd_3d::{math::*, prelude::*, SubstepSchedule, SubstepSet}; pub struct CharacterControllerPlugin; @@ -41,7 +54,9 @@ pub struct CharacterController { pub jump_impulse: Scalar, pub gravity: Vector, pub max_slope_angle: Scalar, - pub speed_limit: f32, + pub axis_speed_limit: f32, + pub max_acceleration: f32, + pub friction: f32, } impl Default for CharacterController { @@ -53,7 +68,10 @@ impl Default for CharacterController { jump_impulse: 4.0, gravity: Vector::NEG_Y * 9.81 * 2.0, max_slope_angle: (45.0 as Scalar).to_radians(), - speed_limit: 6668.5, + axis_speed_limit: 6668.5, + max_acceleration: 857.25, + friction: 0.0, + } } } @@ -65,7 +83,7 @@ pub struct CharacterControllerBundle { collider: Collider, ground_caster: ShapeCaster, restitution: Restitution, - player_look_rotatatable: PlayerLookRotatatable, + player_look_rotatable: PlayerLookRotatable, } impl CharacterControllerBundle { @@ -85,7 +103,7 @@ impl CharacterControllerBundle { ) .with_max_time_of_impact(0.2), restitution: Restitution::new(0.0).with_combine_rule(CoefficientCombine::Min), - player_look_rotatatable: PlayerLookRotatatable, + player_look_rotatable: PlayerLookRotatable, } } } @@ -103,13 +121,13 @@ impl Default for CharacterControllerBundle { fn get_lateral_acceleration( controller: &CharacterController, delta_time: f32, - velocity: LinearVelocity, + velocity: Vec3, ) -> Vec3 { - // No acceleration in Z + // No acceleration in Y let fall_acceleration = Vec3::new( controller.gravity.x, 0.0, - controller.gravity.y, + controller.gravity.z, ); // Bound acceleration, falling object has minimal ability to impact acceleration @@ -171,38 +189,63 @@ fn apply_gravity( for (character_controller, mut linear_velocity) in &mut controllers { - let fall_acceleration: Vec3 = get_lateral_acceleration(character_controller, delta_time, linear_velocity); + let fall_acceleration: Vec3 = get_lateral_acceleration(character_controller, delta_time, linear_velocity.0); fall_acceleration.y = 0.0; let has_limited_air_control: bool = false; // Ugly fix for mismatch types, find a proper solution later - let new_velocity: Vec3 = new_fall_velocity(linear_velocity.clone(), character_controller.gravity, delta_time, character_controller.speed_limit); + let new_velocity: Vec3 = new_fall_velocity(linear_velocity.clone(), character_controller.gravity, delta_time, character_controller.axis_speed_limit); linear_velocity.x = new_velocity.x; linear_velocity.y = new_velocity.y; linear_velocity.z = new_velocity.z; } } +fn move_character( + time: Res