Correct distance calculation between colliders.
This commit is contained in:
parent
4495174be0
commit
c0a1befd98
15
src/core.rs
15
src/core.rs
|
@ -9,8 +9,7 @@ use std::{
|
||||||
|
|
||||||
use bevy::{ecs::query::WorldQuery, prelude::*, utils::FloatOrd};
|
use bevy::{ecs::query::WorldQuery, prelude::*, utils::FloatOrd};
|
||||||
use bevy_rapier2d::{
|
use bevy_rapier2d::{
|
||||||
na,
|
parry::query::{closest_points, distance, ClosestPoints},
|
||||||
parry::query::ClosestPoints,
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
rapier::{math::Isometry, prelude::AABB},
|
rapier::{math::Isometry, prelude::AABB},
|
||||||
};
|
};
|
||||||
|
@ -504,19 +503,15 @@ impl GlobalTransformExt for GlobalTransform {
|
||||||
(other.translation() / *scale).xy().into(),
|
(other.translation() / *scale).xy().into(),
|
||||||
other_rotation.to_scaled_axis().z,
|
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,
|
&pos1,
|
||||||
&*collider.raw,
|
&*collider.raw,
|
||||||
&pos2,
|
&pos2,
|
||||||
&*other_collider.raw,
|
&*other_collider.raw,
|
||||||
f32::MAX,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap() as u32;
|
||||||
let distance: u32 = match closest {
|
|
||||||
ClosestPoints::Intersecting => 0,
|
|
||||||
ClosestPoints::WithinMargin(p1, p2) => na::distance(&p1, &p2) as u32,
|
|
||||||
ClosestPoints::Disjoint => 0,
|
|
||||||
};
|
|
||||||
let tile_or_tiles = if distance == 1 { "tile" } else { "tiles" };
|
let tile_or_tiles = if distance == 1 { "tile" } else { "tiles" };
|
||||||
if distance > 0 {
|
if distance > 0 {
|
||||||
if let ClosestPoints::WithinMargin(p1, p2) = closest {
|
if let ClosestPoints::WithinMargin(p1, p2) = closest {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user