dimforge / dimforge/bevy_rapier

Possible imprecision in cast_shape

Open
#119 2 comments 0 reactions 0 assignees View on GitHub
A-Geometry C-Bug D-Difficult dependencies P-High S-not-started
Dominant language
Rust
Stars
1.6k
Forks
282
PR merge metrics
No merged PRs in 30d

Description

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
```rust
ColliderShape::cuboid(500.0, 1.0, 500.0)
```

I do a vertical sphere cast from above the floor via
```rust
fn test_sphere_cast(
q_pipeline: Res,
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.