diff --git a/src/entities/tasks/executor.rs b/src/entities/tasks/executor.rs index b29bd03..955b6df 100644 --- a/src/entities/tasks/executor.rs +++ b/src/entities/tasks/executor.rs @@ -146,10 +146,25 @@ 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(|&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, - trunk_pos.z as f32 + 1.0, + ground_z, )); ambulatory.current_path = None; }