Fix breakout example bug - ball flighlying out when collide paddle and wall at the same time#685
Conversation
|
Yeah I think the current approach to collisions is pretty naive / breaks easily. But in this case I wasn't able to repro, despite doing this and letting it bounce for a long time (10 minutes): I think the "ball flying out" problem is more a result of framerate dips (resulting in large deltas + missed collisions) than duplicate collisions, and the only way to fix that is to build a more complicated collision system. Regardless of whether or not this pr fixes a bug, I think I'd rather not add too many "special collision cases" to example games to hack around the limitations of the collision system, as they're intended to be extremely simple illustrations of game logic. I'd rather focus our energy on making the collision system itself better (or adopting a third party solution like ncollide for collisions) |
|
I think you need to try it as setting the bar length slightly shorter to have some gap facing the wall, perhaps use a bar length of 855 or 850, then as long as the ball touches the narrow gap, it flies away (takes like 10 or 30 seconds for me to see it.) I think this could be a bad initial experiences or impression towards the engine when someone new here to try it out the code example for the first time. I just started looking at bevy yesterday, tried to run the first breakout example then while I played it for a few seconds I encountered the bug. Or maybe I was lucky. But initially I had a feeling that this game engine is not "reliable". If there is a simple way to fix this, while not making the code look too much difficult to read, perhaps we should do it? |
|
Cool I was able to repro with that advice. You're right about "perceived quality" being important and I guess this isn't particularly complicated. Can we change the match statement to this instead? // break if this collide is on a solid, otherwise continue check whether a solid is also in collision
if let Collider::Solid = *collider {
break;
} |
|
But yeah if there is a way to make the collision system better or even easier to use, then of course that would be a better solution over all. What I am afraid is others might having the same first impression that "it is buggy" if they just try out the first example then encounter a bug like this. |
|
Sure I can update the code. Thank you for the input 👍 |
|
Even though this make it less buggy but it might still not being perfect yet as when I tried out this solution, very few occasions it still can go out. But at least it is much more robust for now. Looking forward to a better collision system later then 👍 |
…ll at the same time (bevyengine#685) Fix breakout bug - ball flying out when collide paddle and wall
|
@liufuyang please respond in #2373 for the relicense to MIT/Apache 2.0. Thanks! |
Updates the requirements on [petgraph](https://github.com/petgraph/petgraph) to permit the latest version. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/petgraph/petgraph/blob/master/RELEASES.rst">petgraph's changelog</a>.</em></p> <blockquote> <h1>Version 0.7.1 (2025-01-08)</h1> <ul> <li>Do not unnecessarily restrict <code>indexmap</code> version (<code>[#714](https://github.com/petgraph/petgraph/issues/714)</code>_)</li> <li>Export <code>UndirectedAdaptor</code> (<code>[#717](https://github.com/petgraph/petgraph/issues/717)</code>_)</li> </ul> <p>.. _<code>[#714](https://github.com/petgraph/petgraph/issues/714)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/714">petgraph/petgraph#714</a> .. _<code>[#717](https://github.com/petgraph/petgraph/issues/717)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/717">petgraph/petgraph#717</a></p> <h1>Version 0.7.0 (2024-12-31)</h1> <ul> <li>Re-released version 0.6.6 with the correct version number, as it included a major update to an exposed crate (<code>[#664](https://github.com/petgraph/petgraph/issues/664)</code>_).</li> </ul> <h1>Version 0.6.6 (2024-12-31 - yanked)</h1> <ul> <li>Add graph6 format encoder and decoder (<code>[#658](https://github.com/petgraph/petgraph/issues/658)</code>_)</li> <li>Dynamic Topological Sort algorithm support (<code>[#675](https://github.com/petgraph/petgraph/issues/675)</code>_)</li> <li>Add <code>UndirectedAdaptor</code> (<code>[#695](https://github.com/petgraph/petgraph/issues/695)</code>_)</li> <li>Add <code>LowerHex</code> and <code>UpperHex</code> implementations for <code>Dot</code> (<code>[#687](https://github.com/petgraph/petgraph/issues/687)</code>_)</li> <li>Make <code>serde</code> support more complete (<code>[#550](https://github.com/petgraph/petgraph/issues/550)</code>_)</li> <li>Process multiple edges in the Floyd-Warshall implementation (<code>[#685](https://github.com/petgraph/petgraph/issues/685)</code>_)</li> <li>Update <code>fixedbitset</code> to 0.5.7 (<code>[#664](https://github.com/petgraph/petgraph/issues/664)</code>_)</li> <li>Fix <code>immediately_dominated_by</code> function called on root of graph returns root itself (<code>[#670](https://github.com/petgraph/petgraph/issues/670)</code>_)</li> <li>Fix adjacency matrix for <code>Csr</code> and <code>List</code> (<code>[#648](https://github.com/petgraph/petgraph/issues/648)</code>_)</li> <li>Fix clippy warnings (<code>[#701](https://github.com/petgraph/petgraph/issues/701)</code>_)</li> <li>Add performance note to the <code>all_simple_paths</code> function documentation (<code>[#693](https://github.com/petgraph/petgraph/issues/693)</code>_)</li> </ul> <p>.. _<code>[#658](https://github.com/petgraph/petgraph/issues/658)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/658">petgraph/petgraph#658</a> .. _<code>[#675](https://github.com/petgraph/petgraph/issues/675)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/675">petgraph/petgraph#675</a> .. _<code>[#695](https://github.com/petgraph/petgraph/issues/695)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/695">petgraph/petgraph#695</a> .. _<code>[#687](https://github.com/petgraph/petgraph/issues/687)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/687">petgraph/petgraph#687</a> .. _<code>[#550](https://github.com/petgraph/petgraph/issues/550)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/550">petgraph/petgraph#550</a> .. _<code>[#685](https://github.com/petgraph/petgraph/issues/685)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/685">petgraph/petgraph#685</a> .. _<code>[#664](https://github.com/petgraph/petgraph/issues/664)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/664">petgraph/petgraph#664</a> .. _<code>[#670](https://github.com/petgraph/petgraph/issues/670)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/670">petgraph/petgraph#670</a> .. _<code>[#648](https://github.com/petgraph/petgraph/issues/648)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/648">petgraph/petgraph#648</a> .. _<code>[#701](https://github.com/petgraph/petgraph/issues/701)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/701">petgraph/petgraph#701</a> .. _<code>[#693](https://github.com/petgraph/petgraph/issues/693)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/693">petgraph/petgraph#693</a></p> <h1>Version 0.6.5 (2024-05-06)</h1> <ul> <li>Add rayon support for <code>GraphMap</code> (<code>[#573](https://github.com/petgraph/petgraph/issues/573)</code><em>, <code>[#615](https://github.com/petgraph/petgraph/issues/615)</code></em>)</li> <li>Add <code>Topo::with_initials</code> method (<code>[#585](https://github.com/petgraph/petgraph/issues/585)</code>_)</li> <li>Add logo to the project (<code>[#598](https://github.com/petgraph/petgraph/issues/598)</code>_)</li> <li>Add Ford-Fulkerson algorithm (<code>[#640](https://github.com/petgraph/petgraph/issues/640)</code>_)</li> <li>Update <code>itertools</code> to 0.12.1 (<code>[#628](https://github.com/petgraph/petgraph/issues/628)</code>_)</li> <li>Update <code>GraphMap</code> to allow custom hash functions (<code>[#622](https://github.com/petgraph/petgraph/issues/622)</code>_)</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/petgraph/petgraph/commit/2765d2a55044a35a20d95c50a2f318fbc3bb85f4"><code>2765d2a</code></a> Release 0.7.1 (<a href="https://redirect.github.com/petgraph/petgraph/issues/722">#722</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/d341db9d18582cfcffebf320896947e55ecba09c"><code>d341db9</code></a> ci: downgrade hashbrown rather than limiting indexmap (<a href="https://redirect.github.com/petgraph/petgraph/issues/714">#714</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/73c64b629f38dc8b0a8edc7550f16a662ed05c25"><code>73c64b6</code></a> Make UndirectedAdaptor & inner G pub (<a href="https://redirect.github.com/petgraph/petgraph/issues/717">#717</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/d057429081bc02812d3605d1e7159f0e73361e51"><code>d057429</code></a> Release <code>0.7.0</code> (<a href="https://redirect.github.com/petgraph/petgraph/issues/713">#713</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/13ebd7d2ddd4a1ac07a33606c0d4f82d342e5fa6"><code>13ebd7d</code></a> Release <code>0.6.6</code> (<a href="https://redirect.github.com/petgraph/petgraph/issues/706">#706</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/159341e4af2a1292d8a1da428d64784e2dfc8ae5"><code>159341e</code></a> Implement DSatur graph coloring algorithm</li> <li><a href="https://github.com/petgraph/petgraph/commit/7fa3aac97168de7fca54644a5b45c464d5245535"><code>7fa3aac</code></a> fix: adjacency matrix for csr and adjacency list (<a href="https://redirect.github.com/petgraph/petgraph/issues/648">#648</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/9fda6bbe2e52663d03317083d2623faa4f0d4cd4"><code>9fda6bb</code></a> Update gitignore with possible editor extensions to ensure they do not occur ...</li> <li><a href="https://github.com/petgraph/petgraph/commit/9b5837e395c342e9cb2e5a2b3870fa7ee6650ef4"><code>9b5837e</code></a> Allow clippy::needless_range_loop in benches</li> <li><a href="https://github.com/petgraph/petgraph/commit/ad9f83c2ae237ba6f5832a19f01ef8c3ae14dd19"><code>ad9f83c</code></a> Process warnings in 'test' target</li> <li>Additional commits viewable in <a href="https://github.com/petgraph/petgraph/compare/petgraph@v0.6.0...petgraph@v0.7.1">compare view</a></li> </ul> </details> <br /> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>



It seems there is a bug of the breakout example, that when ball is collided with both paddle and the wall, the velocity is evaluated and reflected with paddle first, then that
breakwill stop it evaluate if there is other collisions, then the ball will just fly out of the wall.It is easy to see the bug if you try hold the ball between the paddle and the bottom wall then follow it until the ball hits left or right wall. Then there is a good chance when ball hit paddle and left/right wall at the same time then just flying off the walls.
This should fix this bug in some degree but might not prevent other potential bugs related to this. For example the ball might hit the corner of two walls and only one axis of velocity will change and it might still able to fly off the walls. I was also thinking about collect all the possible collisions then do proper velocity change based on all the current possible collisions, but that might name the code a bit too complicated for an intro example?