diff --git a/scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua b/scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua index eecc77c8..5f1ab4b2 100644 --- a/scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua +++ b/scripts/ai/strategies/AIDriveStrategyUnloadCombine.lua @@ -2175,7 +2175,16 @@ function AIDriveStrategyUnloadCombine:onBlockingVehicle(blockingVehicle, isBack) -- with an offset from the combine that makes sure we are clear. Use the trailer's root node (and not -- the tractor's) as when we reversing, it is easier when the trailer remains on the same side of the combine local dx, _, _ = localToLocal(referenceObject.rootNode, blockingVehicle:getAIDirectionNode(), 0, 0, 0) - local xOffset = self.vehicle.size.width / 2 + blockingVehicle:getCpDriveStrategy():getWorkWidth() / 2 + 2 + -- articulated harvesters can stand bent, with the rear part sticking out sideways from + -- the direction node - make sure the offset also clears the widest component, not just + -- the work width around the front part + local maxComponentOffset = 0 + for _, component in pairs(blockingVehicle.components) do + local cdx, _, _ = localToLocal(component.node, blockingVehicle:getAIDirectionNode(), 0, 0, 0) + maxComponentOffset = math.max(maxComponentOffset, math.abs(cdx) + blockingVehicle.size.width / 2) + end + local xOffset = self.vehicle.size.width / 2 + + math.max(blockingVehicle:getCpDriveStrategy():getWorkWidth() / 2, maxComponentOffset) + 2 xOffset = dx > 0 and xOffset or -xOffset self:setNewState(self.states.MOVING_AWAY_FROM_OTHER_VEHICLE) self.state.properties.vehicle = blockingVehicle