Compare commits
2 Commits
07e745c3fc
...
5e700a74b0
Author | SHA1 | Date | |
---|---|---|---|
5e700a74b0 | |||
4de359ffdb |
30
src/core.rs
30
src/core.rs
|
@ -471,6 +471,14 @@ impl From<&dyn PointLike> for (i32, i32) {
|
|||
|
||||
pub trait GlobalTransformExt {
|
||||
fn yaw(&self) -> Angle;
|
||||
|
||||
fn closest_points(
|
||||
&self,
|
||||
collider: &Collider,
|
||||
other: &GlobalTransform,
|
||||
other_collider: &Collider,
|
||||
) -> ClosestPoints;
|
||||
|
||||
fn collider_direction_and_distance(
|
||||
&self,
|
||||
collider: &Collider,
|
||||
|
@ -485,6 +493,25 @@ impl GlobalTransformExt for GlobalTransform {
|
|||
Angle::Radians(forward.y.atan2(forward.x))
|
||||
}
|
||||
|
||||
fn closest_points(
|
||||
&self,
|
||||
collider: &Collider,
|
||||
other: &GlobalTransform,
|
||||
other_collider: &Collider,
|
||||
) -> ClosestPoints {
|
||||
use bevy::math::Vec3Swizzles;
|
||||
let scale = PHYSICS_SCALE.read().unwrap();
|
||||
let pos1 = Isometry::new(
|
||||
(self.translation() / *scale).xy().into(),
|
||||
self.yaw().radians(),
|
||||
);
|
||||
let pos2 = Isometry::new(
|
||||
(other.translation() / *scale).xy().into(),
|
||||
other.yaw().radians(),
|
||||
);
|
||||
closest_points(&pos1, &*collider.raw, &pos2, &*other_collider.raw, f32::MAX).unwrap()
|
||||
}
|
||||
|
||||
fn collider_direction_and_distance(
|
||||
&self,
|
||||
collider: &Collider,
|
||||
|
@ -501,8 +528,7 @@ impl GlobalTransformExt for GlobalTransform {
|
|||
(other.translation() / *scale).xy().into(),
|
||||
other.yaw().radians(),
|
||||
);
|
||||
let closest =
|
||||
closest_points(&pos1, &*collider.raw, &pos2, &*other_collider.raw, f32::MAX).unwrap();
|
||||
let closest = self.closest_points(collider, other, other_collider);
|
||||
let distance = distance(&pos1, &*collider.raw, &pos2, &*other_collider.raw).unwrap() as u32;
|
||||
let tile_or_tiles = if distance == 1 { "tile" } else { "tiles" };
|
||||
if distance > 0 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user