Update Spacing

This commit is contained in:
2026-02-07 16:51:05 -05:00
parent ada75f8479
commit c275cf55dd
2 changed files with 50 additions and 14 deletions

View File

@@ -2,4 +2,5 @@ if not TowBarMod then TowBarMod = {} end
if not TowBarMod.Config then TowBarMod.Config = {} end
TowBarMod.Config.lowLevelAnimation = "RemoveGrass"
TowBarMod.Config.rigidTowbarDistance = 1.0

View File

@@ -89,15 +89,36 @@ function TowBarMod.Utils.updateAttachmentsForRigidTow(towingVehicle, towedVehicl
towedAttachment:setZOffset(0)
local towedModData = towedVehicle:getModData()
local alreadyShifted = towedModData["isChangedTowedAttachment"] and towedModData["towBarChangedAttachmentId"] == attachmentB
if not alreadyShifted then
local spacingDistance = 1.0
if TowBarMod.Config and tonumber(TowBarMod.Config.rigidTowbarDistance) ~= nil then
spacingDistance = tonumber(TowBarMod.Config.rigidTowbarDistance)
end
local offset = towedAttachment:getOffset()
local zShift = offset:z() > 0 and 1 or -1
towedAttachment:getOffset():set(offset:x(), offset:y(), offset:z() + zShift)
local storedBaseX = tonumber(towedModData["towBarBaseAttachmentOffsetX"])
local storedBaseY = tonumber(towedModData["towBarBaseAttachmentOffsetY"])
local storedBaseZ = tonumber(towedModData["towBarBaseAttachmentOffsetZ"])
local hasStoredBase = towedModData["towBarBaseAttachmentId"] == attachmentB
and storedBaseX ~= nil and storedBaseY ~= nil and storedBaseZ ~= nil
local baseX = hasStoredBase and storedBaseX or offset:x()
local baseY = hasStoredBase and storedBaseY or offset:y()
local baseZ = hasStoredBase and storedBaseZ or offset:z()
if not hasStoredBase then
towedModData["towBarBaseAttachmentId"] = attachmentB
towedModData["towBarBaseAttachmentOffsetX"] = baseX
towedModData["towBarBaseAttachmentOffsetY"] = baseY
towedModData["towBarBaseAttachmentOffsetZ"] = baseZ
end
local zDirection = baseZ >= 0 and 1 or -1
local zShift = zDirection * spacingDistance
towedAttachment:getOffset():set(baseX, baseY, baseZ + zShift)
towedModData["isChangedTowedAttachment"] = true
towedModData["towBarChangedAttachmentId"] = attachmentB
towedModData["towBarChangedOffsetZShift"] = zShift
end
towedVehicle:transmitModData()
end
@@ -119,6 +140,15 @@ function TowBarMod.Utils.updateAttachmentsOnDefaultValues(towingVehicle, towedVe
towedAttachment:setZOffset(zOffset)
if towedModData["isChangedTowedAttachment"] then
local storedBaseX = tonumber(towedModData["towBarBaseAttachmentOffsetX"])
local storedBaseY = tonumber(towedModData["towBarBaseAttachmentOffsetY"])
local storedBaseZ = tonumber(towedModData["towBarBaseAttachmentOffsetZ"])
local hasStoredBase = towedModData["towBarBaseAttachmentId"] == changedAttachmentId
and storedBaseX ~= nil and storedBaseY ~= nil and storedBaseZ ~= nil
if hasStoredBase then
towedAttachment:getOffset():set(storedBaseX, storedBaseY, storedBaseZ)
else
local offset = towedAttachment:getOffset()
local storedShift = tonumber(towedModData["towBarChangedOffsetZShift"])
if storedShift ~= nil then
@@ -129,10 +159,15 @@ function TowBarMod.Utils.updateAttachmentsOnDefaultValues(towingVehicle, towedVe
end
end
end
end
towedModData["isChangedTowedAttachment"] = false
towedModData["towBarChangedAttachmentId"] = nil
towedModData["towBarChangedOffsetZShift"] = nil
towedModData["towBarBaseAttachmentId"] = nil
towedModData["towBarBaseAttachmentOffsetX"] = nil
towedModData["towBarBaseAttachmentOffsetY"] = nil
towedModData["towBarBaseAttachmentOffsetZ"] = nil
towedVehicle:transmitModData()
end