fix
This commit is contained in:
@@ -146,25 +146,32 @@ pub fn task_executor_system(
|
||||
continue;
|
||||
}
|
||||
if ambulatory.target.is_none() {
|
||||
// Find the actual ground level at the trunk's XY for pathfinding.
|
||||
// Walking to the trunk itself (z + 1.0) may land on an unreachable tile.
|
||||
// Instead, find a standable tile at the trunk's XY location.
|
||||
let ground_z = (0..=4i32)
|
||||
.map(|z| {
|
||||
IVec3::new(
|
||||
trunk_pos.x,
|
||||
trunk_pos.y,
|
||||
z * crate::constants::ITILE_SIZE,
|
||||
)
|
||||
// Find the actual walkable surface above the floor at the trunk's XY.
|
||||
// Scan for a floor tile, then return the z of the tile above it + 1.0
|
||||
// (same pattern as spawn_log_cargo's find_surface_at).
|
||||
use crate::constants::ITILE_SIZE;
|
||||
let target_z = (-3i32..=4i32)
|
||||
.find_map(|z| {
|
||||
let floor_pos =
|
||||
IVec3::new(trunk_pos.x, trunk_pos.y, z * ITILE_SIZE);
|
||||
if tilemap_mut.floor_tiles.contains_key(&floor_pos) {
|
||||
let above = IVec3::new(
|
||||
trunk_pos.x,
|
||||
trunk_pos.y,
|
||||
floor_pos.z + ITILE_SIZE,
|
||||
);
|
||||
if tilemap_mut.is_standable(above) {
|
||||
return Some(above.z as f32 + 1.0);
|
||||
}
|
||||
}
|
||||
None
|
||||
})
|
||||
.find(|&pos| tilemap_mut.is_standable(pos))
|
||||
.map(|pos| pos.z as f32 + 1.0)
|
||||
.unwrap_or(trunk_pos.z as f32 + 1.0);
|
||||
|
||||
ambulatory.target = Some(Vec3::new(
|
||||
trunk_pos.x as f32,
|
||||
trunk_pos.y as f32,
|
||||
ground_z,
|
||||
target_z,
|
||||
));
|
||||
ambulatory.current_path = None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user