Skip to content

Commit

Permalink
fix jump logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rewin123 committed Nov 4, 2023
1 parent ca7c0fb commit 6671ce3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions examples/platformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,20 @@ fn move_player(

target_vel *= controller.speed;

if keyboard_input.pressed(KeyCode::Space) && !controller.jumped {
target_vel += up * controller.jump_speed;


//smooth change vel
let mut cur_vel = vel.0;
cur_vel = vel.0 + (target_vel - cur_vel) * 10.0 * time.delta_seconds();

if keyboard_input.just_pressed(KeyCode::Space) && !controller.jumped {
cur_vel += up * controller.jump_speed / 6.0;
controller.jumped = true;
}
if !keyboard_input.pressed(KeyCode::Space) {
if !keyboard_input.just_pressed(KeyCode::Space) {
controller.jumped = false;
}

//smooth change vel
let cur_vel = vel.0;
let cur_vel = vel.0 + (target_vel - cur_vel) * 10.0 * time.delta_seconds();
vel.0 = cur_vel;
}
}
Expand Down

0 comments on commit 6671ce3

Please sign in to comment.