From cfb8b29d3470d4f573063d95661b9c296662cd75 Mon Sep 17 00:00:00 2001 From: Fuyang Liu Date: Thu, 15 Oct 2020 23:23:03 +0200 Subject: [PATCH] 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 --- examples/game/breakout.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 4d32fa67628202..c1ea6c3d018e55 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -33,6 +33,7 @@ struct Scoreboard { enum Collider { Solid, Scorable, + Paddle, } fn setup( @@ -53,7 +54,7 @@ fn setup( ..Default::default() }) .with(Paddle { speed: 500.0 }) - .with(Collider::Solid) + .with(Collider::Paddle) // ball .spawn(SpriteComponents { material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()), @@ -240,7 +241,10 @@ fn ball_collision_system( *velocity.y_mut() = -velocity.y(); } - break; + // break if this collide is on a solid, otherwise continue check whether a solid is also in collision + if let Collider::Solid = *collider { + break; + } } } }