Fix path finding calculation of starting point

When a chaser's route finishes calculating, the chaser may already be a
few blocks away from the starting position, thanks to movement inertia.
The path finding code finds the point along the route closest to the
chaser's position.

This calculation only considered the xy coordinates when finding the
closest point. This caused issues whenever the calculated route goes
below the chaser's position (for example, when the chaser is on top of a
bridge and the route circled around to go under the bridge). In this
case, there was a chance that the closest point was the one below the
bridge. This caused the chaser to try to move directly to a directly
inaccessible block.

The fix was to remove the xy() filter so that the closest point
algorithm also considered the z coordinate.
This commit is contained in:
Hugo Peixoto 2022-05-14 14:56:36 +01:00
parent b681ad79ce
commit 74d4e4f45e

View File

@ -428,10 +428,7 @@ impl Chaser {
.iter()
.enumerate()
.min_by_key(|(_, node)| {
node.xy()
.map(|e| e as f32)
.distance_squared(pos.xy() + tgt_dir)
as i32
node.map(|e| e as f32).distance_squared(pos + tgt_dir) as i32
})
.map(|(idx, _)| idx);