Skip to content

ball escapes arena in breakout example #1240

@tigregalis

Description

@tigregalis

Bevy version

master

Operating system & version

Windows 10 / web

What you did

Just let it run for a while.

What you expected to happen

Ball stays in the arena.

What actually happened

Ball escapes the arena.

Additional information

There are three scenarios where this can happen (for each direction). Example below given for ball travelling downward.

https://github.com/bevyengine/bevy/blob/master/crates/bevy_sprite/src/collide_aabb.rs#L32-L40

        // check to see if we hit on the top or bottom side
        let (y_collision, y_depth) = if a_min.y < b_min.y && a_max.y > b_min.y && a_max.y < b_max.y
        {
            (Some(Collision::Bottom), b_min.y - a_max.y)
        } else if a_min.y > b_min.y && a_min.y < b_max.y && a_max.y > b_max.y {
            (Some(Collision::Top), a_min.y - b_max.y)
        } else {
            (None, 0.0)
        };

image

I suspect that at lower frame rates (or fluctuating timesteps) + high ball velocity, the ball "teleports" greater distances between frames so this can happen more often.

There is also an additional scenario where the ball can collide with two walls at once, but because we break out of the collision detection loop when Collider::Solid = *collider, it bounces off one wall into the other (and then next frame you get one of the scenarios above).

The simplest fix to the example would be to make the wall thickness thicker (at least as thick as the ball), but it doesn't really address the collision detection (which I understand is just a temporary thing).

Some code (and screenshots) to see what collisions are happening: https://gist.github.com/tigregalis/fcf99c587134f382c16ab42edc64af1c

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorC-ExamplesAn addition or correction to our examples

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions