clean up player grounding detection
This commit is contained in:
parent
c73b3c7066
commit
6a63d13395
1 changed files with 6 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
use bevy::{
|
||||
prelude::*,
|
||||
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
||||
utils::{HashMap, HashSet},
|
||||
};
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
||||
|
@ -46,19 +47,17 @@ pub fn player_ground_collision(
|
|||
mut collision_events: EventReader<CollisionEvent>,
|
||||
) {
|
||||
let (p, mut player) = player.single_mut();
|
||||
let scene_objs = scene_objs.iter().collect::<HashSet<_>>();
|
||||
|
||||
for collision_event in collision_events.read() {
|
||||
match collision_event {
|
||||
CollisionEvent::Started(e1, e2, _) => {
|
||||
if (e1 == &p && scene_objs.iter().any(|obj| *e2 == obj))
|
||||
|| (e2 == &p && scene_objs.iter().any(|obj| *e1 == obj))
|
||||
{
|
||||
if (e1 == &p && scene_objs.contains(e2)) || (e2 == &p && scene_objs.contains(e1)) {
|
||||
player.grounded = true;
|
||||
}
|
||||
}
|
||||
CollisionEvent::Stopped(e1, e2, _) => {
|
||||
if (e1 == &p && scene_objs.iter().any(|obj| *e2 == obj))
|
||||
|| (e2 == &p && scene_objs.iter().any(|obj| *e1 == obj))
|
||||
{
|
||||
if (e1 == &p && scene_objs.contains(e2)) || (e2 == &p && scene_objs.contains(e1)) {
|
||||
player.grounded = false;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +90,7 @@ pub fn move_player(
|
|||
|
||||
if kb_input.pressed(KeyCode::KeyW) && player.grounded {
|
||||
moved = true;
|
||||
*vel = Velocity::linear(Vec2::new(0., 9. * METER));
|
||||
*vel = Velocity::linear(Vec2::new(0., 9. * METER));
|
||||
// *vel = Velocity::linear(Vec2::new(0., 9.81 * METER));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue