Update Spacing
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 offset = towedAttachment:getOffset()
|
||||
local zShift = offset:z() > 0 and 1 or -1
|
||||
towedAttachment:getOffset():set(offset:x(), offset:y(), offset:z() + zShift)
|
||||
towedModData["isChangedTowedAttachment"] = true
|
||||
towedModData["towBarChangedAttachmentId"] = attachmentB
|
||||
towedModData["towBarChangedOffsetZShift"] = zShift
|
||||
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 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
|
||||
towedVehicle:transmitModData()
|
||||
end
|
||||
|
||||
@@ -119,13 +140,23 @@ function TowBarMod.Utils.updateAttachmentsOnDefaultValues(towingVehicle, towedVe
|
||||
towedAttachment:setZOffset(zOffset)
|
||||
|
||||
if towedModData["isChangedTowedAttachment"] then
|
||||
local offset = towedAttachment:getOffset()
|
||||
local storedShift = tonumber(towedModData["towBarChangedOffsetZShift"])
|
||||
if storedShift ~= nil then
|
||||
towedAttachment:getOffset():set(offset:x(), offset:y(), offset:z() - storedShift)
|
||||
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 zShift = offset:z() > 0 and -1 or 1
|
||||
towedAttachment:getOffset():set(offset:x(), offset:y(), offset:z() + zShift)
|
||||
local offset = towedAttachment:getOffset()
|
||||
local storedShift = tonumber(towedModData["towBarChangedOffsetZShift"])
|
||||
if storedShift ~= nil then
|
||||
towedAttachment:getOffset():set(offset:x(), offset:y(), offset:z() - storedShift)
|
||||
else
|
||||
local zShift = offset:z() > 0 and -1 or 1
|
||||
towedAttachment:getOffset():set(offset:x(), offset:y(), offset:z() + zShift)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -133,6 +164,10 @@ function TowBarMod.Utils.updateAttachmentsOnDefaultValues(towingVehicle, towedVe
|
||||
towedModData["isChangedTowedAttachment"] = false
|
||||
towedModData["towBarChangedAttachmentId"] = nil
|
||||
towedModData["towBarChangedOffsetZShift"] = nil
|
||||
towedModData["towBarBaseAttachmentId"] = nil
|
||||
towedModData["towBarBaseAttachmentOffsetX"] = nil
|
||||
towedModData["towBarBaseAttachmentOffsetY"] = nil
|
||||
towedModData["towBarBaseAttachmentOffsetZ"] = nil
|
||||
towedVehicle:transmitModData()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user