Fix breakout example bug - ball flying out when collide paddle and wall at the same time (#685)

Fix breakout bug - ball flying out when collide paddle and wall
This commit is contained in:
Fuyang Liu 2020-10-15 23:23:03 +02:00 committed by GitHub
parent 90ea5b1e6b
commit 9db8ae7a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,7 @@ struct Scoreboard {
enum Collider { enum Collider {
Solid, Solid,
Scorable, Scorable,
Paddle,
} }
fn setup( fn setup(
@ -53,7 +54,7 @@ fn setup(
..Default::default() ..Default::default()
}) })
.with(Paddle { speed: 500.0 }) .with(Paddle { speed: 500.0 })
.with(Collider::Solid) .with(Collider::Paddle)
// ball // ball
.spawn(SpriteComponents { .spawn(SpriteComponents {
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()), material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
@ -240,8 +241,11 @@ fn ball_collision_system(
*velocity.y_mut() = -velocity.y(); *velocity.y_mut() = -velocity.y();
} }
// break if this collide is on a solid, otherwise continue check whether a solid is also in collision
if let Collider::Solid = *collider {
break; break;
} }
} }
} }
}
} }