Advertisement
Guest User

Untitled

a guest
Oct 30th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.74 KB | None | 0 0
  1.                     --//AC6 Ported Plugin [SS6]//--
  2.                   --//SecondLogic x INSPARE 2017//--
  3.  
  4.  
  5. --------------------------------------------------------------------------
  6.  
  7. local _WHEELTUNE = {
  8.                                                                         --[[   
  9.             SS6 Presets
  10.     [Eco]      
  11.         WearSpeed = 1,
  12.         TargetFriction = .7,
  13.         MinFriction = .1,
  14.     [Road]     
  15.         WearSpeed = 2,
  16.         TargetFriction = .7,
  17.         MinFriction = .1,
  18.     [Sport]    
  19.         WearSpeed = 3,
  20.         TargetFriction = .79,
  21.         MinFriction = .1,                                           ]]
  22.  
  23.     TireWearOn      = true  ,
  24.    
  25.     --Friction and Wear
  26.     FWearSpeed      = 5.0   ,
  27.     FTargetFriction = 1.1   ,
  28.     FMinFriction    = .5    ,
  29.    
  30.     RWearSpeed      = 9.0   ,
  31.     RTargetFriction = 2.0   ,
  32.     RMinFriction    = .5    ,
  33.    
  34.     --Tire Slip
  35.     TCSOffRatio     = 1/3   ,
  36.     WheelLockRatio  = 1/2   ,   --SS6 Default = 1/4
  37.     WheelspinRatio  = 1/1.1 ,   --SS6 Default = 1/1.2
  38.    
  39.     --Wheel Properties
  40.     FFrictionWeight = 1     ,   --SS6 Default = 1
  41.     RFrictionWeight = 1     ,   --SS6 Default = 1
  42.     FLgcyFrWeight   = 10    ,
  43.     RLgcyFrWeight   = 10    ,
  44.    
  45.     FElasticity     = 0     ,   --SS6 Default = .5
  46.     RElasticity     = 0     ,   --SS6 Default = .5
  47.     FLgcyElasticity = 0     ,
  48.     RLgcyElasticity = 0     ,
  49.    
  50.     FElastWeight    = 1     ,   --SS6 Default = 1
  51.     RElastWeight    = 1     ,   --SS6 Default = 1
  52.     FLgcyElWeight   = 10    ,
  53.     RLgcyElWeight   = 10    ,
  54.    
  55.     --Wear Regen
  56.     RegenSpeed      = 9.8       --SS6 Default = 3.6
  57. }
  58.  
  59. --------------------------------------------------------------------------
  60.  
  61.  
  62. local car = script.Parent.Parent.Car.Value
  63. local _Tune = require(car["A-Chassis Tune"])
  64. local cValues = script.Parent.Parent:WaitForChild("Values")
  65.  
  66. --Wheels Array
  67. local fDensity = _Tune.FWheelDensity
  68. local rDensity = _Tune.RWheelDensity
  69. local fFwght = _WHEELTUNE.FFrictionWeight
  70. local rFwght = _WHEELTUNE.RFrictionWeight
  71. local fElast = _WHEELTUNE.FElasticity
  72. local rElast = _WHEELTUNE.RElasticity
  73. local fEwght = _WHEELTUNE.FElastWeight
  74. local rEwght = _WHEELTUNE.RElastWeight
  75. if not workspace:PGSIsEnabled() then
  76.     fDensity = _Tune.FWLgcyDensity
  77.     rDensity = _Tune.RWLgcyDensity
  78.     fFwght = _WHEELTUNE.FLgcyFrWeight
  79.     rFwght = _WHEELTUNE.FLgcyFrWeight
  80.     fElast = _WHEELTUNE.FLgcyElasticity
  81.     rElast = _WHEELTUNE.RLgcyElasticity
  82.     fEwght = _WHEELTUNE.FLgcyElWeight
  83.     rEwght = _WHEELTUNE.RLgcyElWeight
  84. end
  85. local Wheels = {}
  86. for i,v in pairs(car.Wheels:GetChildren()) do
  87.     local w = {}
  88.     w.wheel = v
  89.     local ca
  90.     w.x = 0
  91.     if v.Name == "FL" or v.Name == "FR" or v.Name == "F" then
  92.         ca = (12-math.abs(_Tune.FCamber))/15
  93.         w.x = fDensity
  94.         w.BaseHeat = _WHEELTUNE.FTargetFriction-_WHEELTUNE.FMinFriction
  95.         w.WearSpeed = _WHEELTUNE.FWearSpeed
  96.         w.fWeight = fFwght
  97.         w.elast = fElast
  98.         w.eWeight = fEwght
  99.     else
  100.         ca = (12-math.abs(_Tune.RCamber))/15
  101.         w.x = rDensity
  102.         w.BaseHeat = _WHEELTUNE.RTargetFriction-_WHEELTUNE.RMinFriction
  103.         w.WearSpeed = _WHEELTUNE.RWearSpeed
  104.         w.fWeight = rFwght
  105.         w.elast = rElast
  106.         w.eWeight = rEwght
  107.     end
  108.     --if car:FindFirstChild("WearData")~=nil then
  109.     --  w.Heat = math.min(w.BaseHeat,car.WearData[v.Name].Value+(((tick()-car.WearData.STime.Value)*_WHEELTUNE.RegenSpeed*15/10000)))
  110.     --else
  111.         w.Heat = w.BaseHeat
  112.     --end
  113.     w.stress = 0
  114.     table.insert(Wheels,w)
  115. end
  116.  
  117. --Close/Store Wear Data
  118. car.DriveSeat.ChildRemoved:connect(function(child)
  119.     if child.Name=="SeatWeld" then
  120.         local wD=car:FindFirstChild("WearData")
  121.         if car:FindFirstChild("WearData")==nil then
  122.             wD = script.Parent.WearData:Clone()
  123.             wD.Parent=car
  124.         end
  125.         for i,v in pairs(Wheels) do
  126.             wD[v.wheel.Name].Value = v.Heat
  127.         end
  128.         wD.STime.Value=tick()
  129.     end
  130. end)
  131.  
  132. --Runtime Loop
  133. while wait() do
  134.     for i,v in pairs(Wheels) do
  135.         --Vars
  136.         local speed = car.DriveSeat.Velocity.Magnitude
  137.         local wheel = v.wheel.RotVelocity.Magnitude
  138.         local z = 0    
  139.         local deg = 0.000126
  140.        
  141.         --Tire Wear
  142.         local cspeed = (speed/1.298)*(2.6/v.wheel.Size.Y)
  143.         local wdif = math.abs(wheel-cspeed)
  144.         if _WHEELTUNE.TireWearOn then
  145.             if speed < 4 then
  146.                 --Wear Regen
  147.                 v.Heat = math.min(v.Heat + _WHEELTUNE.RegenSpeed/10000,v.BaseHeat)
  148.             else
  149.                 --Tire Wear
  150.                 if wdif > 1 then
  151.                     v.Heat = v.Heat - wdif*deg*v.WearSpeed/28
  152.                 elseif v.Heat >= v.BaseHeat then
  153.                     v.Heat = v.BaseHeat
  154.                 end
  155.             end
  156.         end
  157.        
  158.         --Apply Friction
  159.         if v.wheel.Name == "FL" or v.wheel.Name == "FR" or v.wheel.Name == "F" then
  160.             z = _WHEELTUNE.FMinFriction+v.Heat
  161.             deg = ((deg - 0.0001188*cValues.Brake.Value)*(1-math.abs(cValues.SteerC.Value))) + 0.00000126*math.abs(cValues.SteerC.Value)
  162.         else
  163.             z = _WHEELTUNE.RMinFriction+v.Heat
  164.         end
  165.        
  166.         --Tire Slip
  167.         if math.ceil((wheel/0.774/speed)*100) < 8 then
  168.             --Lock Slip
  169.             v.wheel.CustomPhysicalProperties = PhysicalProperties.new(v.x,z*_WHEELTUNE.WheelLockRatio,v.elast,v.fWeight,v.eWeight)
  170.             v.Heat = math.max(v.Heat,0)
  171.         elseif (_Tune.TCSEnabled and cValues.TCS.Value == false and math.ceil((wheel/0.774/speed)*100) > 80) then
  172.             --TCS Off
  173.             v.wheel.CustomPhysicalProperties = PhysicalProperties.new(v.x,z*_WHEELTUNE.TCSOffRatio,v.elast,v.fWeight,v.eWeight)
  174.             v.Heat = math.max(v.Heat,0)
  175.         elseif math.ceil((wheel/0.774/speed)*100) > 130 then
  176.             --Wheelspin
  177.             v.wheel.CustomPhysicalProperties = PhysicalProperties.new(v.x,z*_WHEELTUNE.WheelspinRatio,v.elast,v.fWeight,v.eWeight)     
  178.             v.Heat = math.max(v.Heat,0)
  179.         else
  180.             --No Slip
  181.             v.wheel.CustomPhysicalProperties = PhysicalProperties.new(v.x,z,v.elast,v.fWeight,v.eWeight)
  182.             v.Heat = math.min(v.Heat,v.BaseHeat)
  183.         end
  184.        
  185.         --Update UI
  186.         local vstress = math.abs(((((wdif+cspeed)/0.774)*0.774)-cspeed)/15)
  187.         if vstress > 0.05 and vstress > v.stress then
  188.             v.stress = math.min(v.stress + 0.03,1)
  189.         else
  190.             v.stress = math.max(v.stress - 0.03,vstress)   
  191.         end
  192.         local UI = script.Parent.Tires[v.wheel.Name]
  193.         UI.First.Second.Image.ImageColor3 = Color3.new(math.min((v.stress*2),1), 1-v.stress, 0)
  194.         UI.First.Position = UDim2.new(0,0,1-v.Heat/v.BaseHeat,0)
  195.         UI.First.Second.Position = UDim2.new(0,0,v.Heat/v.BaseHeat,0)
  196.     end
  197. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement