From c0a1befd98ce90ec71aac41b847fec031ce2f88e Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 2 Aug 2022 17:14:51 -0500 Subject: [PATCH] Correct distance calculation between colliders. --- src/core.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/core.rs b/src/core.rs index 70a2fdd..3ab23c0 100644 --- a/src/core.rs +++ b/src/core.rs @@ -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 {