Using PlayerValuesState instead of constants that hold playervalues
This commit is contained in:
parent
20c37e1439
commit
437e512fd5
@ -1,9 +1,9 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
use crate::{logic::core::player::player_movement::{
|
||||
use crate::{logic::core::player::{player_movement::{
|
||||
move_player, PlayerLinearXZState, PlayerLinearYState, PlayerMovementInput,
|
||||
}, ui::game::settings::SettingsScreenUIConfiguration};
|
||||
}, player_values_state::PlayerValuesState}, ui::game::settings::SettingsScreenUIConfiguration};
|
||||
|
||||
use super::markers::player::Player;
|
||||
|
||||
@ -23,6 +23,7 @@ pub fn capture_input(
|
||||
>,
|
||||
time: Res<Time>,
|
||||
settings_screen_config: Res<SettingsScreenUIConfiguration>,
|
||||
player_values_state: Res<PlayerValuesState>
|
||||
) {
|
||||
// Don't allocate on each frame. Instead Check if any of the inputs are being pressed and then allocate.
|
||||
if keyboard_input.any_pressed([
|
||||
@ -50,9 +51,9 @@ pub fn capture_input(
|
||||
sprint: keyboard_input.pressed(KeyCode::ShiftLeft),
|
||||
};
|
||||
if settings_screen_config.settings_menu_shown {
|
||||
move_player(PlayerMovementInput::default(), player_query, time);
|
||||
move_player(PlayerMovementInput::default(), player_query, time, player_values_state);
|
||||
} else {
|
||||
move_player(player_movement_input, player_query, time);
|
||||
move_player(player_movement_input, player_query, time, player_values_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
pub mod player_values;
|
@ -1,25 +0,0 @@
|
||||
pub const MAX_LINEAR_PLAYER_VELOCITY: f32 = 20.0;
|
||||
pub const PLAYER_ACCELERATION: f32 = 20.0;
|
||||
pub const PLAYER_JUMP_FORCE: f32 = 900.0;
|
||||
/// Time in ms that player must be grounded in order to jump again
|
||||
pub const PLAYER_JUMP_COOLDOWN_MS: u128 = 75;
|
||||
pub const PLAYER_SPRINT_SPEED_MULTIPLIER: f32 = 3.5;
|
||||
pub const PLAYER_CROUCH_SPEED_MULTIPLIER: f32 = 0.25;
|
||||
pub const PLAYER_INITIAL_WEIGHT: f32 = 75.0;
|
||||
pub const PLAYER_GRAVITY_SCALE: f32 = 4.0;
|
||||
|
||||
pub const PLAYER_HEIGHT: f32 = 2.5;
|
||||
pub const PLAYER_CAMERA_HEIGHT: f32 = 1.25;
|
||||
pub const PLAYER_CROUCH_HEIGHT: f32 = 0.0;
|
||||
pub const PLAYER_CROUCH_TIME_S: f32 = 1.25;
|
||||
|
||||
pub const PLAYER_LINEAR_DAMPING: f32 = 3.5;
|
||||
pub const PLAYER_LINEAR_DAMPING_WHILE_JUMPING: f32 = 0.25;
|
||||
|
||||
pub const PLAYER_LEAN_TIME: f32 = 0.3;
|
||||
pub const PLAYER_LEAN_ANGLE: f32 = 30.0;
|
||||
|
||||
pub const PLAYER_LATERAL_ACCELERATION_WHILE_SPRINTING_MULTIPLIER: f32 = 0.2;
|
||||
pub const PLAYER_LATERAL_ACCELERATION_MULTIPLIER: f32 = 1.0;
|
||||
|
||||
pub const PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS: u128 = 20;
|
@ -3,11 +3,10 @@ use bevy::{input::mouse::MouseMotion, prelude::*, window::CursorGrabMode};
|
||||
|
||||
use crate::{
|
||||
comps::core::markers::{camera::MainCamera, player::Player},
|
||||
constants::player_values::{PLAYER_CAMERA_HEIGHT, PLAYER_CROUCH_HEIGHT, PLAYER_CROUCH_TIME_S, PLAYER_LEAN_TIME, PLAYER_LEAN_ANGLE},
|
||||
utils::rad_deg::radians_from_degrees, ui::game::settings::SettingsScreenUIConfiguration,
|
||||
};
|
||||
|
||||
use super::player_movement::PlayerLinearXZState;
|
||||
use super::{player_movement::PlayerLinearXZState, player_values_state::PlayerValuesState};
|
||||
|
||||
/// Mouse sensitivity and movement speed
|
||||
#[derive(Resource)]
|
||||
@ -32,6 +31,7 @@ pub fn update_camera_vertical_position(
|
||||
mut player: Query<(&mut Transform, &PlayerLinearXZState), (With<Player>, Without<MainCamera>)>,
|
||||
mut camera: Query<&mut Transform, (With<MainCamera>, Without<Player>)>,
|
||||
time: Res<Time>,
|
||||
player_values_state: Res<PlayerValuesState>,
|
||||
) {
|
||||
let Ok((_, player_linear_xz_state)) = player.get_single_mut() else {
|
||||
return;
|
||||
@ -46,17 +46,17 @@ pub fn update_camera_vertical_position(
|
||||
camera_transform.translation = camera_transform.translation.lerp(
|
||||
Vec3 {
|
||||
x: camera_transform.translation.x,
|
||||
y: PLAYER_CROUCH_HEIGHT,
|
||||
y: player_values_state.player_crouch_height,
|
||||
z: camera_transform.translation.z,
|
||||
},
|
||||
(delta / PLAYER_CROUCH_TIME_S).clamp(0.0, 1.0),
|
||||
(delta / player_values_state.player_crouch_time_s).clamp(0.0, 1.0),
|
||||
);
|
||||
} else {
|
||||
// TODO: Add elapsed time to standup so that crouch time and standup time is the same.
|
||||
camera_transform.translation = camera_transform.translation.lerp(
|
||||
Vec3 {
|
||||
x: camera_transform.translation.x,
|
||||
y: PLAYER_CAMERA_HEIGHT,
|
||||
y: player_values_state.player_camera_height,
|
||||
z: camera_transform.translation.z,
|
||||
},
|
||||
time.delta_seconds().clamp(0.0, 1.0),
|
||||
@ -75,6 +75,7 @@ pub fn follow_cursor_with_camera(
|
||||
btn: Res<Input<MouseButton>>,
|
||||
time: Res<Time>,
|
||||
mut settings_screen_config: ResMut<SettingsScreenUIConfiguration>,
|
||||
player_values_state: Res<PlayerValuesState>,
|
||||
) {
|
||||
if let Ok(mut window) = primary_window.get_single_mut() {
|
||||
if keyboard_input.just_pressed(KeyCode::Escape) {
|
||||
@ -130,28 +131,28 @@ pub fn follow_cursor_with_camera(
|
||||
let right = Vec3::new(local_z.z, camera_transform.translation.y, -local_z.x);
|
||||
player_transform.rotation = desired_rotation_quat;
|
||||
if keyboard_input.pressed(KeyCode::Q) {
|
||||
let final_quat = Quat::from_axis_angle(Vec3::Z, radians_from_degrees(PLAYER_LEAN_ANGLE));
|
||||
let final_quat = Quat::from_axis_angle(Vec3::Z, radians_from_degrees(player_values_state.player_lean_angle));
|
||||
camera_transform.rotation = camera_transform
|
||||
.rotation
|
||||
.lerp(final_quat, time.delta_seconds() / PLAYER_LEAN_TIME);
|
||||
camera_transform.translation = camera_transform.translation.lerp(Vec3 { x: -right.x, y: camera_transform.translation.y, z: -right.z }, time.delta_seconds() / PLAYER_LEAN_TIME);
|
||||
.lerp(final_quat, time.delta_seconds() / player_values_state.player_lean_time);
|
||||
camera_transform.translation = camera_transform.translation.lerp(Vec3 { x: -right.x, y: camera_transform.translation.y, z: -right.z }, time.delta_seconds() / player_values_state.player_lean_time);
|
||||
} else if keyboard_input.pressed(KeyCode::E) {
|
||||
let final_quat =
|
||||
Quat::from_axis_angle(Vec3::Z, radians_from_degrees(-PLAYER_LEAN_ANGLE));
|
||||
Quat::from_axis_angle(Vec3::Z, radians_from_degrees(-player_values_state.player_lean_angle));
|
||||
camera_transform.rotation = camera_transform
|
||||
.rotation
|
||||
.lerp(final_quat, time.delta_seconds() / PLAYER_LEAN_TIME);
|
||||
camera_transform.translation = camera_transform.translation.lerp(Vec3 { x: right.x, y: camera_transform.translation.y, z: right.z }, time.delta_seconds() / PLAYER_LEAN_TIME);
|
||||
.lerp(final_quat, time.delta_seconds() / player_values_state.player_lean_time);
|
||||
camera_transform.translation = camera_transform.translation.lerp(Vec3 { x: right.x, y: camera_transform.translation.y, z: right.z }, time.delta_seconds() / player_values_state.player_lean_time);
|
||||
} else {
|
||||
camera_transform.rotation = camera_transform
|
||||
.rotation
|
||||
.lerp(Quat::default(), time.delta_seconds() / PLAYER_LEAN_TIME);
|
||||
.lerp(Quat::default(), time.delta_seconds() / player_values_state.player_lean_time);
|
||||
|
||||
camera_transform.translation = camera_transform.translation.lerp(Vec3 {
|
||||
x: 0.0,
|
||||
y: camera_transform.translation.y,
|
||||
z: 0.0,
|
||||
}, time.delta_seconds() / PLAYER_LEAN_TIME);
|
||||
}, time.delta_seconds() / player_values_state.player_lean_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,3 +3,4 @@ pub mod camera_player_sync;
|
||||
pub mod hands;
|
||||
pub mod player_movement;
|
||||
pub mod player_vertical_sync;
|
||||
pub mod player_values_state;
|
@ -3,24 +3,20 @@ use bevy_rapier3d::prelude::*;
|
||||
|
||||
use crate::{
|
||||
comps::core::markers::player::Player,
|
||||
constants::player_values::{
|
||||
MAX_LINEAR_PLAYER_VELOCITY, PLAYER_ACCELERATION, PLAYER_CROUCH_SPEED_MULTIPLIER,
|
||||
PLAYER_JUMP_COOLDOWN_MS, PLAYER_JUMP_FORCE, PLAYER_LATERAL_ACCELERATION_MULTIPLIER,
|
||||
PLAYER_LATERAL_ACCELERATION_WHILE_SPRINTING_MULTIPLIER,
|
||||
PLAYER_LINEAR_DAMPING_WHILE_JUMPING, PLAYER_SPRINT_SPEED_MULTIPLIER,
|
||||
},
|
||||
};
|
||||
|
||||
use super::player_values_state::PlayerValuesState;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub enum PlayerLinearYState {
|
||||
Grounded(u128),
|
||||
Grounded(f64),
|
||||
Jumping,
|
||||
Falling,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
impl PlayerLinearYState {
|
||||
pub fn is_grounded(&self, longer_than: &u128) -> bool {
|
||||
pub fn is_grounded(&self, longer_than: &f64) -> bool {
|
||||
match self {
|
||||
Self::Grounded(time_grounded) => time_grounded > longer_than,
|
||||
_ => false,
|
||||
@ -71,7 +67,7 @@ impl PlayerLinearXZState {
|
||||
}
|
||||
/*/// If already sprinting, adds time to sprint
|
||||
/// If not sprinting sets sprint.
|
||||
pub fn sprint(&mut self, time: u128) {
|
||||
pub fn sprint(&mut self, time: u64) {
|
||||
match self {
|
||||
PlayerLinearXZState::Sprinting(since) => {},
|
||||
_ => *self = PlayerLinearXZState::Sprinting(time)
|
||||
@ -115,6 +111,7 @@ pub fn move_player(
|
||||
With<Player>,
|
||||
>,
|
||||
time: Res<Time>,
|
||||
player_values_state: Res<PlayerValuesState>
|
||||
) {
|
||||
for (
|
||||
mut player_velocity,
|
||||
@ -129,13 +126,13 @@ pub fn move_player(
|
||||
player_linear_xz_state.toggle_crouch(time.elapsed().as_secs_f32());
|
||||
}
|
||||
let crouch_multiplier = if player_linear_xz_state.is_crouched() {
|
||||
PLAYER_CROUCH_SPEED_MULTIPLIER
|
||||
player_values_state.player_crouch_speed_multiplier
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let sprint_multiplier =
|
||||
if player_movement_input.sprint && !player_linear_xz_state.is_crouched() {
|
||||
PLAYER_SPRINT_SPEED_MULTIPLIER
|
||||
player_values_state.player_sprint_speed_multiplier
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
@ -145,9 +142,9 @@ pub fn move_player(
|
||||
if !player_linear_y_state.is_jumping() && !player_linear_y_state.is_falling() {
|
||||
// Only let player move when grounded
|
||||
if player_movement_input.front {
|
||||
if sprint_multiplier == PLAYER_SPRINT_SPEED_MULTIPLIER {
|
||||
if sprint_multiplier == player_values_state.player_sprint_speed_multiplier {
|
||||
*player_linear_xz_state = PlayerLinearXZState::Sprinting;
|
||||
} else if crouch_multiplier == PLAYER_CROUCH_SPEED_MULTIPLIER {
|
||||
} else if crouch_multiplier == player_values_state.player_crouch_speed_multiplier {
|
||||
} else {
|
||||
*player_linear_xz_state = PlayerLinearXZState::Walking;
|
||||
}
|
||||
@ -156,10 +153,11 @@ pub fn move_player(
|
||||
player_velocity.linvel,
|
||||
time.delta_seconds(),
|
||||
sprint_multiplier * crouch_multiplier,
|
||||
player_values_state.player_acceleration
|
||||
);
|
||||
}
|
||||
if player_movement_input.back {
|
||||
if crouch_multiplier == PLAYER_CROUCH_SPEED_MULTIPLIER {
|
||||
if crouch_multiplier == player_values_state.player_crouch_speed_multiplier {
|
||||
} else {
|
||||
*player_linear_xz_state = PlayerLinearXZState::Walking;
|
||||
}
|
||||
@ -168,10 +166,11 @@ pub fn move_player(
|
||||
player_velocity.linvel,
|
||||
time.delta_seconds(),
|
||||
crouch_multiplier,
|
||||
player_values_state.player_acceleration
|
||||
);
|
||||
}
|
||||
if player_movement_input.right {
|
||||
if crouch_multiplier == PLAYER_CROUCH_SPEED_MULTIPLIER {
|
||||
if crouch_multiplier == player_values_state.player_crouch_speed_multiplier {
|
||||
} else {
|
||||
*player_linear_xz_state = PlayerLinearXZState::Walking;
|
||||
}
|
||||
@ -180,14 +179,15 @@ pub fn move_player(
|
||||
player_velocity.linvel,
|
||||
time.delta_seconds(),
|
||||
if player_linear_xz_state.is_sprinting() {
|
||||
PLAYER_LATERAL_ACCELERATION_WHILE_SPRINTING_MULTIPLIER * crouch_multiplier
|
||||
player_values_state.player_lateral_acceleration_while_sprinting_multiplier * crouch_multiplier
|
||||
} else {
|
||||
PLAYER_LATERAL_ACCELERATION_MULTIPLIER * crouch_multiplier
|
||||
player_values_state.player_lateral_acceleration_multiplier * crouch_multiplier
|
||||
},
|
||||
player_values_state.player_acceleration
|
||||
);
|
||||
}
|
||||
if player_movement_input.left {
|
||||
if crouch_multiplier == PLAYER_CROUCH_SPEED_MULTIPLIER {
|
||||
if crouch_multiplier == player_values_state.player_crouch_speed_multiplier {
|
||||
} else {
|
||||
*player_linear_xz_state = PlayerLinearXZState::Walking;
|
||||
}
|
||||
@ -196,42 +196,43 @@ pub fn move_player(
|
||||
player_velocity.linvel,
|
||||
time.delta_seconds(),
|
||||
if player_linear_xz_state.is_sprinting() {
|
||||
PLAYER_LATERAL_ACCELERATION_WHILE_SPRINTING_MULTIPLIER * crouch_multiplier
|
||||
player_values_state.player_lateral_acceleration_while_sprinting_multiplier * crouch_multiplier
|
||||
} else {
|
||||
PLAYER_LATERAL_ACCELERATION_MULTIPLIER * crouch_multiplier
|
||||
player_values_state.player_lateral_acceleration_multiplier * crouch_multiplier
|
||||
},
|
||||
player_values_state.player_acceleration
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if player_movement_input.up && player_linear_y_state.is_grounded(&PLAYER_JUMP_COOLDOWN_MS) {
|
||||
player_external_force.impulse = Vec3::new(0.0, PLAYER_JUMP_FORCE, 0.0);
|
||||
if player_movement_input.up && player_linear_y_state.is_grounded(&player_values_state.player_jump_cooldown_s) {
|
||||
player_external_force.impulse = Vec3::new(0.0, player_values_state.player_jump_force, 0.0);
|
||||
*player_linear_y_state = PlayerLinearYState::Jumping;
|
||||
*player_damping = Damping {
|
||||
linear_damping: PLAYER_LINEAR_DAMPING_WHILE_JUMPING,
|
||||
linear_damping: player_values_state.player_linear_damping_while_jumping,
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
// When player velocity exceeds max linear velocity then set to max_linear_vel value
|
||||
if player_velocity.linvel.x.abs()
|
||||
> MAX_LINEAR_PLAYER_VELOCITY * crouch_multiplier * sprint_multiplier
|
||||
> player_values_state.max_linear_player_velocity * crouch_multiplier * sprint_multiplier
|
||||
{
|
||||
let positive = player_velocity.linvel.x.is_sign_positive();
|
||||
if positive {
|
||||
player_velocity.linvel.x =
|
||||
MAX_LINEAR_PLAYER_VELOCITY * crouch_multiplier * sprint_multiplier
|
||||
player_values_state.max_linear_player_velocity * crouch_multiplier * sprint_multiplier
|
||||
} else {
|
||||
player_velocity.linvel.x = MAX_LINEAR_PLAYER_VELOCITY * -1.0 * crouch_multiplier
|
||||
player_velocity.linvel.x = player_values_state.max_linear_player_velocity * -1.0 * crouch_multiplier
|
||||
}
|
||||
}
|
||||
if player_velocity.linvel.z.abs()
|
||||
> MAX_LINEAR_PLAYER_VELOCITY * crouch_multiplier * sprint_multiplier
|
||||
> player_values_state.max_linear_player_velocity * crouch_multiplier * sprint_multiplier
|
||||
{
|
||||
let positive = player_velocity.linvel.z.is_sign_positive();
|
||||
if positive {
|
||||
player_velocity.linvel.z = MAX_LINEAR_PLAYER_VELOCITY * crouch_multiplier
|
||||
player_velocity.linvel.z = player_values_state.max_linear_player_velocity * crouch_multiplier
|
||||
} else {
|
||||
player_velocity.linvel.z = MAX_LINEAR_PLAYER_VELOCITY * -1.0 * crouch_multiplier
|
||||
player_velocity.linvel.z = player_values_state.max_linear_player_velocity * -1.0 * crouch_multiplier
|
||||
}
|
||||
}
|
||||
if player_velocity.linvel.x > -1.0
|
||||
@ -251,6 +252,7 @@ fn apply_movement_acceleration_to_vec(
|
||||
current_linvel: Vec3,
|
||||
delta_time_secs: f32,
|
||||
multiplier: f32,
|
||||
player_acceleration: f32,
|
||||
) -> Vec3 {
|
||||
current_linvel + (direction * PLAYER_ACCELERATION * delta_time_secs * multiplier)
|
||||
current_linvel + (direction * player_acceleration * delta_time_secs * multiplier)
|
||||
}
|
||||
|
58
src/logic/core/player/player_values_state.rs
Normal file
58
src/logic/core/player/player_values_state.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use bevy::{prelude::{Resource, ReflectResource}, reflect::Reflect};
|
||||
|
||||
|
||||
#[derive(Resource, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
pub struct PlayerValuesState {
|
||||
pub max_linear_player_velocity: f32,
|
||||
pub player_acceleration: f32,
|
||||
pub player_jump_force: f32,
|
||||
|
||||
pub player_jump_cooldown_s: f64,
|
||||
pub player_sprint_speed_multiplier: f32,
|
||||
pub player_crouch_speed_multiplier: f32,
|
||||
pub player_initial_weight: f32,
|
||||
pub player_gravity_scale: f32,
|
||||
|
||||
pub player_height: f32,
|
||||
pub player_camera_height: f32,
|
||||
pub player_crouch_height: f32,
|
||||
pub player_crouch_time_s: f32,
|
||||
|
||||
pub player_linear_damping: f32,
|
||||
pub player_linear_damping_while_jumping: f32,
|
||||
|
||||
pub player_lean_time: f32,
|
||||
pub player_lean_angle: f32,
|
||||
|
||||
pub player_lateral_acceleration_while_sprinting_multiplier: f32,
|
||||
pub player_lateral_acceleration_multiplier: f32,
|
||||
|
||||
pub player_linear_damping_time_offset_after_jump_in_s: f64,
|
||||
}
|
||||
|
||||
impl Default for PlayerValuesState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
max_linear_player_velocity: 20.0,
|
||||
player_acceleration: 20.0,
|
||||
player_jump_force: 900.0,
|
||||
player_jump_cooldown_s: 0.075,
|
||||
player_sprint_speed_multiplier: 3.5,
|
||||
player_crouch_speed_multiplier: 0.25,
|
||||
player_initial_weight: 75.0,
|
||||
player_gravity_scale: 4.0,
|
||||
player_height: 2.5,
|
||||
player_camera_height: 1.25,
|
||||
player_crouch_height: 0.0,
|
||||
player_crouch_time_s: 1.25,
|
||||
player_linear_damping: 3.5,
|
||||
player_linear_damping_while_jumping: 0.25,
|
||||
player_lean_time: 0.3,
|
||||
player_lean_angle: 30.0,
|
||||
player_lateral_acceleration_while_sprinting_multiplier: 0.2,
|
||||
player_lateral_acceleration_multiplier: 1.0,
|
||||
player_linear_damping_time_offset_after_jump_in_s: 0.02,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,40 +1,35 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
use crate::{
|
||||
comps::core::markers::player::Player,
|
||||
constants::player_values::{
|
||||
PLAYER_JUMP_COOLDOWN_MS, PLAYER_LINEAR_DAMPING,
|
||||
PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS, PLAYER_LINEAR_DAMPING_WHILE_JUMPING,
|
||||
},
|
||||
};
|
||||
use crate::comps::core::markers::player::Player;
|
||||
|
||||
use super::player_movement::PlayerLinearYState;
|
||||
use super::{player_movement::PlayerLinearYState, player_values_state::PlayerValuesState};
|
||||
|
||||
/// System that captures linear y velocity and determines whether player is falling or grounded, and how long the player has been grounded for.
|
||||
pub fn sync_player_y_state(
|
||||
mut query: Query<(&Velocity, &mut PlayerLinearYState, &mut Damping), With<Player>>,
|
||||
time: Res<Time>,
|
||||
player_values_state: Res<PlayerValuesState>
|
||||
) {
|
||||
for (player_velocity, mut player_linear_y_state, mut player_damping) in &mut query {
|
||||
if player_velocity.linvel.y < -1.0 {
|
||||
*player_linear_y_state = PlayerLinearYState::Falling;
|
||||
*player_damping = Damping {
|
||||
linear_damping: PLAYER_LINEAR_DAMPING_WHILE_JUMPING,
|
||||
linear_damping: player_values_state.player_linear_damping_while_jumping,
|
||||
..Default::default()
|
||||
};
|
||||
} else if player_velocity.linvel.y >= -1.0 && player_velocity.linvel.y <= 1.0 {
|
||||
let previous_grounded_time = match *player_linear_y_state {
|
||||
PlayerLinearYState::Grounded(grounded_for) => grounded_for,
|
||||
_ => 0,
|
||||
_ => 0.0,
|
||||
};
|
||||
let new_grounded_time = previous_grounded_time + time.delta().as_millis();
|
||||
let new_grounded_time = previous_grounded_time + time.delta().as_secs_f64();
|
||||
*player_linear_y_state = PlayerLinearYState::Grounded(new_grounded_time);
|
||||
if new_grounded_time
|
||||
> PLAYER_JUMP_COOLDOWN_MS - PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS
|
||||
> player_values_state.player_jump_cooldown_s - player_values_state.player_linear_damping_time_offset_after_jump_in_s
|
||||
{
|
||||
*player_damping = Damping {
|
||||
linear_damping: PLAYER_LINEAR_DAMPING,
|
||||
linear_damping: player_values_state.player_linear_damping,
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
use bevy_rapier3d::prelude::*;
|
||||
use logic::core::guns::player_firing::PlayerFiringInfo;
|
||||
use logic::core::{guns::player_firing::PlayerFiringInfo, player::player_values_state::PlayerValuesState};
|
||||
use scenes::scene1;
|
||||
use ui::game::plugin::MainGameUIPlugin;
|
||||
|
||||
@ -29,7 +29,8 @@ fn setup_plugins(application: &mut App) {
|
||||
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
|
||||
.add_plugins(WorldInspectorPlugin::new())
|
||||
.add_plugins(MainGameUIPlugin)
|
||||
.register_type::<PlayerFiringInfo>();
|
||||
.register_type::<PlayerFiringInfo>()
|
||||
.register_type::<PlayerValuesState>();
|
||||
}
|
||||
|
||||
fn load(application: &mut App) {
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
follow_cursor_with_camera, update_camera_vertical_position, MouseMovementSettings,
|
||||
},
|
||||
hands::capture_hand_usage,
|
||||
player_vertical_sync::sync_player_y_state,
|
||||
player_vertical_sync::sync_player_y_state, player_values_state::PlayerValuesState,
|
||||
}, setup::{assets::load_all_assets, load_state::GameLoadState, spawn::add_all_spawners, animations::{load_animations, AllFirearmAnimations}, equipment::{EquipmentChangeEvent, change_equipment}},
|
||||
};
|
||||
|
||||
@ -19,6 +19,7 @@ pub fn load_scene(application: &mut App) {
|
||||
application.insert_resource(GameLoadState::default());
|
||||
application.insert_resource(MouseMovementSettings::default());
|
||||
application.insert_resource(AllFirearmAnimations::default());
|
||||
application.insert_resource(PlayerValuesState::default());
|
||||
// Startup
|
||||
application.add_systems(PreStartup, load_all_assets);
|
||||
application.add_systems(Startup, spawn_ground);
|
||||
|
@ -6,9 +6,7 @@ use crate::{
|
||||
camera::MainCamera,
|
||||
player::{Player, PlayerHand, PlayerData},
|
||||
},
|
||||
constants::player_values::{
|
||||
PLAYER_GRAVITY_SCALE, PLAYER_HEIGHT, PLAYER_INITIAL_WEIGHT, PLAYER_LINEAR_DAMPING,
|
||||
}, logic::core::{player::player_movement::{PlayerLinearYState, PlayerLinearXZState}, guns::player_firing::PlayerFiringInfo}, setup::{load_state::GameLoadState, equipment::EquipmentChangeEvent},
|
||||
logic::core::{player::{player_movement::{PlayerLinearYState, PlayerLinearXZState}, player_values_state::PlayerValuesState}, guns::player_firing::PlayerFiringInfo}, setup::{load_state::GameLoadState, equipment::EquipmentChangeEvent},
|
||||
};
|
||||
|
||||
use crate::setup::spawn::SpawnPoint;
|
||||
@ -20,6 +18,7 @@ pub fn player_spawner(
|
||||
player_sp_query: Query<(Entity, &SpawnPoint<Player>)>,
|
||||
mut game_load_state: ResMut<GameLoadState>,
|
||||
mut equipment_change_event_writer: EventWriter<EquipmentChangeEvent>,
|
||||
player_values_state: Res<PlayerValuesState>,
|
||||
) {
|
||||
if game_load_state.player_loaded || !game_load_state.is_everything_except_player_loaded() {
|
||||
return;
|
||||
@ -56,8 +55,8 @@ pub fn player_spawner(
|
||||
.spawn(Player(PlayerData::default()))
|
||||
// Physics
|
||||
.insert(RigidBody::Dynamic)
|
||||
.insert(GravityScale(PLAYER_GRAVITY_SCALE))
|
||||
.insert(Collider::capsule_y(PLAYER_HEIGHT, 2.0))
|
||||
.insert(GravityScale(player_values_state.player_gravity_scale))
|
||||
.insert(Collider::capsule_y(player_values_state.player_height, 2.0))
|
||||
.insert(Restitution::coefficient(0.0))
|
||||
.insert(Friction {
|
||||
coefficient: 0.0,
|
||||
@ -69,7 +68,7 @@ pub fn player_spawner(
|
||||
})
|
||||
.insert(Velocity::zero())
|
||||
.insert(Damping {
|
||||
linear_damping: PLAYER_LINEAR_DAMPING,
|
||||
linear_damping: player_values_state.player_linear_damping,
|
||||
angular_damping: 1.0,
|
||||
})
|
||||
.insert(
|
||||
@ -77,7 +76,7 @@ pub fn player_spawner(
|
||||
| LockedAxes::ROTATION_LOCKED_X
|
||||
| LockedAxes::ROTATION_LOCKED_Y,
|
||||
)
|
||||
.insert(ColliderMassProperties::Mass(PLAYER_INITIAL_WEIGHT))
|
||||
.insert(ColliderMassProperties::Mass(player_values_state.player_initial_weight))
|
||||
.insert(ExternalImpulse {
|
||||
impulse: Vec3::ZERO,
|
||||
torque_impulse: Vec3::ZERO,
|
||||
|
@ -2,6 +2,7 @@ use bevy::prelude::*;
|
||||
|
||||
pub struct MainEditorUIPlugin;
|
||||
|
||||
#[allow(unused)]
|
||||
impl Plugin for MainEditorUIPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
todo!()
|
||||
|
Loading…
Reference in New Issue
Block a user