From 760f6602cf4cdc6198f282c9c0d26fcb50b4ed8d Mon Sep 17 00:00:00 2001 From: popertots Date: Sun, 22 Mar 2026 16:51:20 +0000 Subject: [PATCH] fix --- src/entities/tasks/executor.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/entities/tasks/executor.rs b/src/entities/tasks/executor.rs index 955b6df..b10da3d 100644 --- a/src/entities/tasks/executor.rs +++ b/src/entities/tasks/executor.rs @@ -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; }