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

Possible imprecision in cast_shape #119

Open
FocusJP opened this issue Feb 1, 2022 · 2 comments
Open

Possible imprecision in cast_shape #119

FocusJP opened this issue Feb 1, 2022 · 2 comments
Labels
A-Geometry C-Bug Something isn't working D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... dependencies Pull requests that update a dependency file P-High arbitrary important item S-not-started Work has not started

Comments

@FocusJP
Copy link

FocusJP commented Feb 1, 2022

I'm not sure if this is a real issue or just the reality of floating point precision, but I wanted to at least flag it as suspicious.

I have a simple scene with a floor collider of shape

ColliderShape::cuboid(500.0, 1.0, 500.0)

I do a vertical sphere cast from above the floor via

fn test_sphere_cast(
    q_pipeline: Res<QueryPipeline>,
    q_collider: QueryPipelineColliderComponentsQuery,
){
    let collider_set = QueryPipelineColliderComponentsSet(&q_collider);
    let shape = Ball::new(1.0);
    let start = Isometry::translation(0.0, 3.0, 0.0);
    let direction = vector![0.0, -1.0, 0.0];
    let max_toi = 2.0;
    let groups = InteractionGroups::all();
    let filter = None;

    if let Some((handle, hit)) = q_pipeline.cast_shape(
        &collider_set, &start, &direction, &shape, max_toi, groups, filter
    ){
        let y1 = hit.witness1.y;
        let y2 = start.translation.y + hit.toi * direction.y + hit.witness2.y;
        info!("{} {} {}", hit.toi, y1, y2); 
    }
}

I expect y1 and y2 will both agree on a hit height of ~1.0. In fact, y1 is always within about 1E-7. However, as I vary start.x and start.z in small 0.01 increments I notice that y2 may drift as little as 5E-8 or as much as 6E-2. I don't know the inner workings of the shape cast algorithm, but is this variation expected?

@FocusJP
Copy link
Author

FocusJP commented Feb 10, 2022

Reducing the cuboid dimensions to

ColliderShape::cuboid(20.0, 1.0, 20.0)

dramatically reduced the jitter I am getting. For now my workaround is to break up large floor panels into smaller panels.

@DanielHZhang
Copy link

I'm also running into this issue with cast_shape hit output being imprecise, especially when casting Collider::ball onto large surfaces, which results in a significant amount of jitter.

I made a minimal reproduction of the issue here: https://github.com/DanielHZhang/bevy_rapier_shape_cast_imprecision

Shape.Cast.Jitter.mov

This seems to be caused by rapier itself, and not just the bevy plugin: dimforge/rapier#434

@Vrixyz Vrixyz added C-Bug Something isn't working dependencies Pull requests that update a dependency file D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-High arbitrary important item S-not-started Work has not started A-Geometry labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Geometry C-Bug Something isn't working D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... dependencies Pull requests that update a dependency file P-High arbitrary important item S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

3 participants