variable jump height
This commit is contained in:
parent
e7e1242ef4
commit
78acd0313c
1 changed files with 8 additions and 3 deletions
|
@ -26,12 +26,14 @@ struct RespawnPointSetEvent;
|
|||
#[derive(Component)]
|
||||
struct Player {
|
||||
move_cooldown: Timer,
|
||||
last_grounded: u64,
|
||||
}
|
||||
|
||||
impl Default for Player {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
move_cooldown: Timer::from_seconds(0.01, TimerMode::Repeating),
|
||||
last_grounded: u64::MAX / 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +96,9 @@ fn move_player(
|
|||
let mut move_y = 0;
|
||||
let mut jump = false;
|
||||
let grounded = output.is_ok_and(|x| x.grounded);
|
||||
if grounded {
|
||||
player.last_grounded = 0;
|
||||
}
|
||||
if kb_input.pressed(KeyCode::KeyA) {
|
||||
moved = true;
|
||||
move_x -= 1;
|
||||
|
@ -103,8 +108,7 @@ fn move_player(
|
|||
move_x += 1;
|
||||
}
|
||||
if (kb_input.pressed(KeyCode::Space) || kb_input.pressed(KeyCode::KeyW))
|
||||
&& vel.linvel.y < 0.1
|
||||
&& grounded
|
||||
&& player.last_grounded <= 5
|
||||
{
|
||||
moved = true;
|
||||
move_y += 1;
|
||||
|
@ -114,7 +118,7 @@ fn move_player(
|
|||
cam_transform.translation -= ((orig - p_transform.translation.xy().extend(0.0)) / 30.0);
|
||||
|
||||
controller.translation = Some(Vec2::new(move_x as f32 * 6., 0. - 0.01));
|
||||
vel.linvel += Vec2::new(0., move_y as f32 * 6. * METER);
|
||||
vel.linvel += Vec2::new(0., move_y as f32 * METER);
|
||||
|
||||
if move_x != 0 && grounded {
|
||||
*anim_state = PlayerAnimations::Walk;
|
||||
|
@ -142,6 +146,7 @@ fn move_player(
|
|||
p_transform.translation =
|
||||
Vec2::new(player_coords.x, player_coords.y).extend(PLAYER_DEPTH);
|
||||
}
|
||||
player.last_grounded += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue