Fix player movement
This commit is contained in:
parent
307cb748d5
commit
03781e3dc8
1 changed files with 44 additions and 43 deletions
|
@ -73,6 +73,7 @@ impl Player {
|
|||
|
||||
let mut new_position = self.view.camera.position;
|
||||
|
||||
if !self.creative {
|
||||
// y component (jumping)
|
||||
new_position.y += velocity.y;
|
||||
if let Some(aabb) = self.check_collision(new_position, world) {
|
||||
|
@ -86,7 +87,7 @@ impl Player {
|
|||
|
||||
self.up_speed = 0.0;
|
||||
self.grounded = true;
|
||||
} else {
|
||||
} else if self.up_speed.abs() > 0.05 {
|
||||
self.grounded = false;
|
||||
}
|
||||
|
||||
|
@ -114,12 +115,12 @@ impl Player {
|
|||
}
|
||||
}
|
||||
|
||||
self.view.camera.position = new_position;
|
||||
|
||||
if !self.creative {
|
||||
self.up_speed -= 1.6 * dt.as_secs_f32();
|
||||
self.up_speed *= 0.98_f32.powf(dt.as_secs_f32() / 20.0);
|
||||
} else {
|
||||
new_position += velocity;
|
||||
}
|
||||
self.view.camera.position = new_position;
|
||||
}
|
||||
|
||||
fn check_collision(&self, position: Point3<f32>, world: &World) -> Option<Aabb> {
|
||||
|
|
Loading…
Reference in a new issue