Skip to content

Commit

Permalink
fix case where contacts are missed (#278)
Browse files Browse the repository at this point in the history
- Fixes: #262
Before the points reported were in local space instead of global space.
  • Loading branch information
Ughuuu authored Oct 13, 2024
1 parent 9b31fcb commit db38058
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
crate-type = ["cdylib"]

[features]
default = ["build3d", "test"]
default = ["build2d", "test"]
test = []
build2d = ["single-dim2", "serde-serialize", "simd-stable"]
build3d = ["single-dim3", "serde-serialize", "simd-stable"]
Expand Down
20 changes: 18 additions & 2 deletions src/rapier_wrapper/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::ops::Mul;

use godot::global::godot_error;
use godot::global::godot_warn;
use nalgebra::zero;
use rapier::parry;
use rapier::parry::query::ShapeCastOptions;
use rapier::parry::query::ShapeCastStatus;
use rapier::prelude::*;

use crate::rapier_wrapper::prelude::*;
Expand Down Expand Up @@ -239,6 +241,7 @@ impl PhysicsEngine {
let shape_cast_options = ShapeCastOptions {
max_time_of_impact: 1.0,
stop_at_penetration: true,
compute_impact_geometry_on_penetration: true,
..Default::default()
};
let toi_result = parry::query::cast_shapes(
Expand All @@ -253,12 +256,19 @@ impl PhysicsEngine {
match toi_result {
Ok(None) => {}
Ok(Some(hit)) => {
if hit.status == ShapeCastStatus::Failed
|| hit.status == ShapeCastStatus::OutOfIterations
{
godot_warn!("shape collide status warn: {:?}", hit.status);
}
result.collided = true;
result.toi = hit.time_of_impact;
result.normal1 = hit.normal1.into_inner();
result.normal2 = hit.normal2.into_inner();
result.pixel_witness1 = hit.witness1.coords;
result.pixel_witness2 = hit.witness2.coords;
result.pixel_witness1 =
hit.witness1.coords + shape_info1.transform.translation.vector;
result.pixel_witness2 =
hit.witness2.coords + shape_info2.transform.translation.vector;
}
Err(err) => {
godot_error!("toi error: {:?}", err);
Expand Down Expand Up @@ -307,6 +317,7 @@ impl PhysicsEngine {
let shape_cast_options = ShapeCastOptions {
max_time_of_impact: 1.0,
stop_at_penetration: true,
compute_impact_geometry_on_penetration: true,
..Default::default()
};
if let Some((collider_handle, hit)) =
Expand All @@ -320,6 +331,11 @@ impl PhysicsEngine {
filter,
)
{
if hit.status == ShapeCastStatus::Failed
|| hit.status == ShapeCastStatus::OutOfIterations
{
godot_warn!("shape casting status warn: {:?}", hit.status);
}
result.collided = true;
result.toi = hit.time_of_impact;
result.normal1 = hit.normal1.into_inner();
Expand Down

0 comments on commit db38058

Please sign in to comment.