Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected AabbCast2d aabb_collision_at with small max distance value #17703

Open
bread-mountain4 opened this issue Feb 6, 2025 · 0 comments
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled

Comments

@bread-mountain4
Copy link

Bevy version

0.15.1

[Optional] Relevant system information

  • Arch Linux
  • rustc 1.84.1 (e71f9a9a9 2025-01-27)

What you did

I have some code that uses raycast2d over short distances that I expect to be similar to if I translated the aabb2 then did an intersection check.

What went wrong

I am getting some unexpected results with these raycasts. I get an unexpected value of a collision at distance 0.0 for two Aabb2ds that should be sufficiently far apart.

Here's a small unit test I wrote to do the raycast some other ways that do pass, then the last call I expected to be a None but it's a Some(0.0). The numbers were pulled directly from a live run of the program when the raycast2d returned an unexpected answer.

#[test]
fn test_debug() {
    let movement_amount = 0.974444;

    let window = Aabb2d {
        min: Vec2::new(-26.197449, -21.058212),
        max: Vec2::new(323.80255, 278.94177),
    };
    let side = Aabb2d {
        min: Vec2::new(472.0, -320.0),
        max: Vec2::new(473.0, 320.0),
    };

    assert_eq!(false, window.intersects(&side));
    assert_eq!(false, side.intersects(&window));

    let mut window_new = window.clone();
    window_new.translate_by(Vec2::new(movement_amount, 0.0));
    assert_eq!(false, window_new.intersects(&side));
    assert_eq!(false, side.intersects(&window_new));

    let window_new_new = Aabb2d {
        min: window.min + Vec2::new(movement_amount, 0.0),
        max: window.max + Vec2::new(movement_amount, 0.0),
    };

    assert_eq!(false, window_new_new.intersects(&side));
    assert_eq!(false, side.intersects(&window_new_new));

    let ray_direction = Dir2::new(Vec2::new(1.0, 0.0)).unwrap();
    let ray_towards_boundary_intersections = Ray2d::new(window.center(), ray_direction);
    let bounds_check_ray_cast =
        AabbCast2d::from_ray(window, ray_towards_boundary_intersections, movement_amount);

    let res = bounds_check_ray_cast.aabb_collision_at(side);
    assert_eq!(None, res);
}
---- collisions::tests::test_debug stdout ----
thread 'collisions::tests::test_debug' panicked at scroll_2d/src/collisions/tests.rs:234:5:
assertion `left == right` failed
  left: None
 right: Some(0.0)
@bread-mountain4 bread-mountain4 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled
Projects
None yet
Development

No branches or pull requests

1 participant