hotfix: broken dashing

Former-commit-id: 2a0d1f6fb11d8b1d5525622d200e2f4787f763e4
This commit is contained in:
Muhammad Nauman Raza 2023-12-07 19:00:18 +00:00
parent f3c2bd7a5a
commit 20840a4147
Signed by: devraza
GPG key ID: 91EAD6081011574B
2 changed files with 5 additions and 10 deletions

View file

@ -98,9 +98,5 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
health_max: 10.,
stamina: 1.,
stamina_max: 10.,
defence: 40.,
is_dashing: false,
});
}

View file

@ -10,10 +10,6 @@ pub struct Player {
pub health_max: f32,
pub stamina: f32,
pub stamina_max: f32,
pub defence: f32,
pub is_dashing: bool,
}
// Define the player movement system
@ -40,9 +36,12 @@ pub fn movement(
// Initialise the movement distance variable (to bring it into scope)
let mut movement_distance: f32 = 0.;
// Player is not dashing by default
let mut is_dashing = false;
// Dash on space key press if the player has the stamina
if keys.just_pressed(KeyCode::Space) && player.stamina >= 0.3 {
player.is_dashing = true;
is_dashing = true;
player.stamina -= 0.3;
movement_distance = 256.;
}
@ -66,7 +65,7 @@ pub fn movement(
// Get the player's *forward* vector
let movement_direction = transform.rotation * Vec3::Y;
if !player.is_dashing {
if !is_dashing {
movement_distance = movement_factor * player.movement_speed * time.delta_seconds();
// Change the player rotation around the Z-axis only if not dashing
transform.rotate_z(rotation_factor * player.rotation_speed * time.delta_seconds());