From 2e805b3b8bf9afec65d4dc7b17167a906bb07edb Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 15 Jun 2021 17:48:49 -0500 Subject: [PATCH] Use physics for pathfinding. --- src/pathfinding.rs | 150 +++++++++++++-------------------------------- 1 file changed, 41 insertions(+), 109 deletions(-) diff --git a/src/pathfinding.rs b/src/pathfinding.rs index 129742b..0f9bf7a 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use bevy::{prelude::*, tasks::prelude::*}; -use bevy_rapier2d::prelude::*; +use bevy_rapier2d::{na::UnitComplex, prelude::*}; use crossbeam_channel::{unbounded, Receiver}; use derive_more::{Deref, DerefMut}; use pathfinding::prelude::*; @@ -41,43 +41,6 @@ pub fn find_path( ) } -fn nearest_extreme(from: f32, to: i32) -> f32 { - let to = to as f32; - let range = to..=(to + 0.999); - if from <= *range.start() { - *range.start() - } else { - *range.end() - } -} - -fn cheat_assign( - start: (f32, f32), - end: (i32, i32), - map_width: usize, - motion_blocked: Vec, -) -> Option<(f32, f32)> { - let x; - let y; - if start.0 as i32 == end.0 { - x = start.0; - } else { - x = nearest_extreme(start.0, end.0); - } - if start.1 as i32 == end.1 { - y = start.1; - } else { - y = nearest_extreme(start.1, end.1); - } - let point = (x, y); - let index = point.to_index(map_width); - if motion_blocked[index] { - None - } else { - Some(point) - } -} - fn calculate_path( mut commands: Commands, pool: Res, @@ -117,93 +80,62 @@ fn calculate_path( } } -/*fn negotiate_path( +fn negotiate_path( mut commands: Commands, - time: Res