Correct distance calculation between colliders.

This commit is contained in:
Nolan Darilek 2022-08-02 17:14:51 -05:00
parent 4495174be0
commit c0a1befd98

View File

@ -9,8 +9,7 @@ use std::{
use bevy::{ecs::query::WorldQuery, prelude::*, utils::FloatOrd};
use bevy_rapier2d::{
na,
parry::query::ClosestPoints,
parry::query::{closest_points, distance, ClosestPoints},
prelude::*,
rapier::{math::Isometry, prelude::AABB},
};
@ -504,19 +503,15 @@ impl GlobalTransformExt for GlobalTransform {
(other.translation() / *scale).xy().into(),
other_rotation.to_scaled_axis().z,
);
let closest = bevy_rapier2d::parry::query::closest_points(
let closest =
closest_points(&pos1, &*collider.raw, &pos2, &*other_collider.raw, f32::MAX).unwrap();
let distance = distance(
&pos1,
&*collider.raw,
&pos2,
&*other_collider.raw,
f32::MAX,
)
.unwrap();
let distance: u32 = match closest {
ClosestPoints::Intersecting => 0,
ClosestPoints::WithinMargin(p1, p2) => na::distance(&p1, &p2) as u32,
ClosestPoints::Disjoint => 0,
};
.unwrap() as u32;
let tile_or_tiles = if distance == 1 { "tile" } else { "tiles" };
if distance > 0 {
if let ClosestPoints::WithinMargin(p1, p2) = closest {