Tweaked values and changed cooldown from u64 to 128

This commit is contained in:
Franklin 2023-09-12 10:03:33 -04:00
parent 8e739de9bc
commit 8ed0ba71fe
5 changed files with 9 additions and 9 deletions

View File

@ -10,7 +10,7 @@ pub fn capture_input(keyboard_input: Res<Input<KeyCode>>, query: Query<(&mut Vel
// Don't allocate on each frame. Instead Check if any of the inputs are being pressed and then allocate. // Don't allocate on each frame. Instead Check if any of the inputs are being pressed and then allocate.
if keyboard_input.any_pressed([KeyCode::A, KeyCode::S, KeyCode::D, KeyCode::W, KeyCode::C, KeyCode::Space]) { if keyboard_input.any_pressed([KeyCode::A, KeyCode::S, KeyCode::D, KeyCode::W, KeyCode::C, KeyCode::Space]) {
let player_movement_input = PlayerMovementInput { let player_movement_input = PlayerMovementInput {
up: keyboard_input.pressed(KeyCode::Space), up: keyboard_input.just_pressed(KeyCode::Space),
down: keyboard_input.pressed(KeyCode::C), down: keyboard_input.pressed(KeyCode::C),
left: keyboard_input.pressed(KeyCode::A), left: keyboard_input.pressed(KeyCode::A),
right: keyboard_input.pressed(KeyCode::D), right: keyboard_input.pressed(KeyCode::D),

View File

@ -3,4 +3,4 @@ pub const MAX_LINEAR_PLAYER_VELOCITY: f32 = 10.0;
pub const PLAYER_ACCELERATION: f32 = 10.0; pub const PLAYER_ACCELERATION: f32 = 10.0;
pub const PLAYER_JUMP_FORCE: f32 = 1500.0; pub const PLAYER_JUMP_FORCE: f32 = 1500.0;
/// Time in ms that player must be grounded in order to jump again /// Time in ms that player must be grounded in order to jump again
pub const PLAYER_JUMP_COOLDOWN_MS: u64 = 300; pub const PLAYER_JUMP_COOLDOWN_MS: u128 = 100;

View File

@ -5,17 +5,17 @@ use crate::{comps::core::markers::player::Player, constants::player_values::{MAX
#[derive(Component)] #[derive(Component)]
pub enum PlayerLinearYState { pub enum PlayerLinearYState {
Grounded(u64), Grounded(u128),
Jumping, Jumping,
Falling Falling
} }
#[allow(unused)] #[allow(unused)]
impl PlayerLinearYState { impl PlayerLinearYState {
pub fn is_grounded(&self, longer_than: u64) -> bool { pub fn is_grounded(&self, longer_than: &u128) -> bool {
match self { match self {
Self::Grounded(time_grounded) => { Self::Grounded(time_grounded) => {
time_grounded > &longer_than time_grounded > longer_than
}, },
_ => false _ => false
} }
@ -81,7 +81,7 @@ pub fn move_player(player_movement_input: PlayerMovementInput, mut query: Query<
player_velocity.linvel.x = apply_movement_acceleration(player_velocity.linvel.x, false, time.delta_seconds(), 1.0); player_velocity.linvel.x = apply_movement_acceleration(player_velocity.linvel.x, false, time.delta_seconds(), 1.0);
} }
if player_movement_input.up && player_linear_y_state.is_grounded(PLAYER_JUMP_COOLDOWN_MS) { 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); player_external_force.impulse = Vec3::new(0.0, PLAYER_JUMP_FORCE, 0.0);
*player_linear_y_state = PlayerLinearYState::Jumping; *player_linear_y_state = PlayerLinearYState::Jumping;
} }

View File

@ -7,7 +7,7 @@ use super::player_movement::PlayerLinearYState;
/// System that captures input and fires events /// 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), With<Player>>, time: Res<Time>) { pub fn sync_player_y_state(mut query: Query<(&Velocity, &mut PlayerLinearYState), With<Player>>, time: Res<Time>) {
for (player_velocity, mut player_linear_y_state) in &mut query { for (player_velocity, mut player_linear_y_state) in &mut query {
if player_velocity.linvel.y < -1.0 { if player_velocity.linvel.y < -1.0 {
@ -17,7 +17,7 @@ pub fn sync_player_y_state(mut query: Query<(&Velocity, &mut PlayerLinearYState)
PlayerLinearYState::Grounded(grounded_for) => grounded_for, PlayerLinearYState::Grounded(grounded_for) => grounded_for,
_ => 0 _ => 0
}; };
*player_linear_y_state = PlayerLinearYState::Grounded(previous_grounded_time + time.delta().as_millis() as u64); *player_linear_y_state = PlayerLinearYState::Grounded(previous_grounded_time + time.delta().as_millis());
} }
} }

View File

@ -15,7 +15,7 @@ pub fn spawn_player(mut commands: Commands) {
.insert(TransformBundle::from(Transform::from_xyz(3.0, 5.0, 2.0))) .insert(TransformBundle::from(Transform::from_xyz(3.0, 5.0, 2.0)))
.insert(Velocity::zero()) .insert(Velocity::zero())
.insert(Damping { linear_damping: 1.0, angular_damping: 1.0 }) .insert(Damping { linear_damping: 1.0, angular_damping: 1.0 })
.insert(LockedAxes::ROTATION_LOCKED_X | LockedAxes::ROTATION_LOCKED_Z) .insert(LockedAxes::ROTATION_LOCKED_X | LockedAxes::ROTATION_LOCKED_Z | LockedAxes::ROTATION_LOCKED_Y)
.insert(ColliderMassProperties::Density(2.0)) .insert(ColliderMassProperties::Density(2.0))
.insert(ExternalImpulse { .insert(ExternalImpulse {
impulse: Vec3::ZERO, impulse: Vec3::ZERO,