42.20 and Towtrucks
This commit is contained in:
@@ -3,61 +3,54 @@ BTtow.Create = {}
|
||||
BTtow.Init = {}
|
||||
|
||||
local TowbarVariantSize = 24
|
||||
local TowbarNormalStart = 0
|
||||
local TowbarLargeStart = 24
|
||||
local TowbarMaxIndex = TowbarVariantSize - 1
|
||||
local VanillaScaleMin = 1.5
|
||||
local VanillaScaleMax = 2.0
|
||||
local TowbarFirstZ = 1.0
|
||||
local TowbarSlotStep = 0.1
|
||||
-- Measured from Towbar.fbx at its original 0.01 script scale. Keep this in
|
||||
-- lockstep with the client selector so the enlarged mesh's inner end remains
|
||||
-- on the same vehicle-hitbox contact point.
|
||||
local TowbarVisualScale = 2.5
|
||||
local TowbarModelLength = 0.9714089036
|
||||
local TowbarScaledModelLength = TowbarModelLength * TowbarVisualScale
|
||||
local TowbarModelHalfLength = TowbarScaledModelLength / 2
|
||||
|
||||
local function getVehicleModelScale(script)
|
||||
local function getTowbarFrontEdgeZ(script)
|
||||
if not script then return nil end
|
||||
|
||||
local ok, result = pcall(function()
|
||||
return script:getModelScale()
|
||||
local ok, shape = pcall(function()
|
||||
return script:getPhysicsChassisShape()
|
||||
end)
|
||||
if ok and type(result) == "number" then
|
||||
return result
|
||||
end
|
||||
if not ok or not shape then return nil end
|
||||
|
||||
ok, result = pcall(function()
|
||||
local model = script:getModel()
|
||||
if model then
|
||||
return model:getScale()
|
||||
end
|
||||
local shapeOk, shapeZ = pcall(function()
|
||||
return shape:z()
|
||||
end)
|
||||
if not shapeOk or type(shapeZ) ~= "number" or shapeZ <= 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
local centerOk, center = pcall(function()
|
||||
return script:getCenterOfMassOffset()
|
||||
end)
|
||||
if ok and type(result) == "number" then
|
||||
return result
|
||||
end
|
||||
if not centerOk or not center then return nil end
|
||||
|
||||
return nil
|
||||
end
|
||||
local zOk, centerZ = pcall(function()
|
||||
return center:z()
|
||||
end)
|
||||
if not zOk or type(centerZ) ~= "number" then return nil end
|
||||
|
||||
local function isVanillaScale(script)
|
||||
local modelScale = getVehicleModelScale(script)
|
||||
if modelScale == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
local configuredMin = TowBarMod and TowBarMod.Config and tonumber(TowBarMod.Config.vanillaTowbarModelScaleMin)
|
||||
local configuredMax = TowBarMod and TowBarMod.Config and tonumber(TowBarMod.Config.vanillaTowbarModelScaleMax)
|
||||
local minScale = configuredMin or VanillaScaleMin
|
||||
local maxScale = configuredMax or VanillaScaleMax
|
||||
return modelScale >= minScale and modelScale <= maxScale
|
||||
end
|
||||
|
||||
local function getTowbarIndexVanilla(script)
|
||||
local z = script:getPhysicsChassisShape():z() / 2 - 0.1
|
||||
local index = math.floor((z * 2 / 3 - 1) * 10)
|
||||
return math.max(0, math.min(TowbarMaxIndex, index))
|
||||
return centerZ + shapeZ / 2
|
||||
end
|
||||
|
||||
local function getTowbarModelSlot(script)
|
||||
if not isVanillaScale(script) then
|
||||
-- KI5/small-scale vehicles use the normal towbar0 mesh at Z=1.
|
||||
return 0
|
||||
end
|
||||
return getTowbarIndexVanilla(script)
|
||||
local frontEdgeZ = getTowbarFrontEdgeZ(script)
|
||||
if frontEdgeZ == nil then return nil end
|
||||
|
||||
-- Model offsets position the mesh origin. Move its center outward so the
|
||||
-- towbar's inner end, rather than its center, meets the vehicle hitbox.
|
||||
local modelCenterZ = frontEdgeZ + TowbarModelHalfLength
|
||||
local index = math.floor(((modelCenterZ - TowbarFirstZ) / TowbarSlotStep) + 0.5)
|
||||
return math.max(0, math.min(TowbarMaxIndex, index))
|
||||
end
|
||||
|
||||
function BTtow.Create.towbar(vehicle, part)
|
||||
@@ -81,7 +74,7 @@ function BTtow.Init.towbar(vehicle, part)
|
||||
if script then
|
||||
local index = getTowbarModelSlot(script)
|
||||
local shouldShowOnThisPart = part:getId() == "towbar"
|
||||
if shouldShowOnThisPart then
|
||||
if shouldShowOnThisPart and index ~= nil then
|
||||
part:setModelVisible("towbar" .. index, true)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user