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
|
if not TowBarMod.Config then TowBarMod.Config = {} end
|
||||||
|
|
||||||
TowBarMod.Config.lowLevelAnimation = "RemoveGrass"
|
TowBarMod.Config.lowLevelAnimation = "RemoveGrass"
|
||||||
|
TowBarMod.Config.rigidTowbarDistance = 1.0
|
||||||
|
|
||||||
|
|||||||
@@ -89,15 +89,36 @@ function TowBarMod.Utils.updateAttachmentsForRigidTow(towingVehicle, towedVehicl
|
|||||||
towedAttachment:setZOffset(0)
|
towedAttachment:setZOffset(0)
|
||||||
|
|
||||||
local towedModData = towedVehicle:getModData()
|
local towedModData = towedVehicle:getModData()
|
||||||
local alreadyShifted = towedModData["isChangedTowedAttachment"] and towedModData["towBarChangedAttachmentId"] == attachmentB
|
local spacingDistance = 1.0
|
||||||
if not alreadyShifted then
|
if TowBarMod.Config and tonumber(TowBarMod.Config.rigidTowbarDistance) ~= nil then
|
||||||
|
spacingDistance = tonumber(TowBarMod.Config.rigidTowbarDistance)
|
||||||
|
end
|
||||||
|
|
||||||
local offset = towedAttachment:getOffset()
|
local offset = towedAttachment:getOffset()
|
||||||
local zShift = offset:z() > 0 and 1 or -1
|
local storedBaseX = tonumber(towedModData["towBarBaseAttachmentOffsetX"])
|
||||||
towedAttachment:getOffset():set(offset:x(), offset:y(), offset:z() + zShift)
|
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["isChangedTowedAttachment"] = true
|
||||||
towedModData["towBarChangedAttachmentId"] = attachmentB
|
towedModData["towBarChangedAttachmentId"] = attachmentB
|
||||||
towedModData["towBarChangedOffsetZShift"] = zShift
|
towedModData["towBarChangedOffsetZShift"] = zShift
|
||||||
end
|
|
||||||
towedVehicle:transmitModData()
|
towedVehicle:transmitModData()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -119,6 +140,15 @@ function TowBarMod.Utils.updateAttachmentsOnDefaultValues(towingVehicle, towedVe
|
|||||||
towedAttachment:setZOffset(zOffset)
|
towedAttachment:setZOffset(zOffset)
|
||||||
|
|
||||||
if towedModData["isChangedTowedAttachment"] then
|
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 offset = towedAttachment:getOffset()
|
||||||
local storedShift = tonumber(towedModData["towBarChangedOffsetZShift"])
|
local storedShift = tonumber(towedModData["towBarChangedOffsetZShift"])
|
||||||
if storedShift ~= nil then
|
if storedShift ~= nil then
|
||||||
@@ -129,10 +159,15 @@ function TowBarMod.Utils.updateAttachmentsOnDefaultValues(towingVehicle, towedVe
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
towedModData["isChangedTowedAttachment"] = false
|
towedModData["isChangedTowedAttachment"] = false
|
||||||
towedModData["towBarChangedAttachmentId"] = nil
|
towedModData["towBarChangedAttachmentId"] = nil
|
||||||
towedModData["towBarChangedOffsetZShift"] = nil
|
towedModData["towBarChangedOffsetZShift"] = nil
|
||||||
|
towedModData["towBarBaseAttachmentId"] = nil
|
||||||
|
towedModData["towBarBaseAttachmentOffsetX"] = nil
|
||||||
|
towedModData["towBarBaseAttachmentOffsetY"] = nil
|
||||||
|
towedModData["towBarBaseAttachmentOffsetZ"] = nil
|
||||||
towedVehicle:transmitModData()
|
towedVehicle:transmitModData()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user