--Tires

function GetTireCurve(c,x) return (((-math.abs(x^(c*2.4)))/2.4)+((-math.abs(x^2.4))/2.4))*(7/6) end

function WFriction(v,val)
	if v.CustomPhysicalProperties == nil then v.CustomPhysicalProperties = PhysicalProperties.new(v.Material) end
	v.CustomPhysicalProperties = PhysicalProperties.new(0,val,0,.1,0)
end

Instance.new("Model",fWheel.Parts).Name = "Tires"
Instance.new("Model",rWheel.Parts).Name = "Tires"

for i=0,_Tune.TireCylinders do
	local fCyl = fWheel:Clone()
	fCyl.Name = "FTire"
	for _,a in pairs(fCyl:GetChildren()) do a:Destroy() end
	fCyl.Parent = fWheel.Parts.Tires
	if _Tune.TiresVisible or _Tune.Debug then fCyl.Transparency = 0 else fCyl.Transparency = 1 end
	fCyl.Size = Vector3.new(fWheel.Size.X*(i/_Tune.TireCylinders),fWheel.Size.Y+(_Tune.FProfileHeight*GetTireCurve(_Tune.FTireProfile,i/_Tune.TireCylinders)),fWheel.Size.Y+(_Tune.FProfileHeight*GetTireCurve(_Tune.FTireProfile,i/_Tune.TireCylinders)))
	
	if (i/_Tune.TireCylinders < 1/3 and _Tune.FTireCompound == 3) or (i/_Tune.TireCylinders < 1/2 and _Tune.FTireCompound == 2) then
		WFriction(fCyl,_Tune.FTireFriction-.1)
		fCyl.Name = fCyl.Name.."L"
	elseif i/_Tune.TireCylinders >= 1/3 and i/_Tune.TireCylinders < 2/3 and _Tune.FTireCompound == 3 then
		WFriction(fCyl,(_Tune.FTireFriction+(_Tune.FTireFriction-.1))/2)
		fCyl.Name = fCyl.Name.."M"
	elseif i/_Tune.TireCylinders >= 2/3 or (i/_Tune.TireCylinders >= 1/2 and _Tune.FTireCompound == 2) or _Tune.FTireCompound == 1 then
		WFriction(fCyl,_Tune.FTireFriction)
		fCyl.Name = fCyl.Name.."H"
	end
	
	local rCyl = rWheel:Clone()
	rCyl.Name = "RTire"
	for _,b in pairs(rCyl:GetChildren()) do b:Destroy() end
	rCyl.Parent = rWheel.Parts.Tires
	if _Tune.TiresVisible or _Tune.Debug then rCyl.Transparency = 0 else rCyl.Transparency = 1 end
	rCyl.Size = Vector3.new(rWheel.Size.X*(i/_Tune.TireCylinders),rWheel.Size.Y+(_Tune.RProfileHeight*GetTireCurve(_Tune.RTireProfile,i/_Tune.TireCylinders)),rWheel.Size.Y+(_Tune.RProfileHeight*GetTireCurve(_Tune.RTireProfile,i/_Tune.TireCylinders)))
	
	if (i/_Tune.TireCylinders < 1/3 and _Tune.RTireCompound == 3) or (i/_Tune.TireCylinders < 1/2 and _Tune.RTireCompound == 2) then
		WFriction(rCyl,_Tune.RTireFriction-.1)
		rCyl.Name = rCyl.Name.."L"
	elseif i/_Tune.TireCylinders >= 1/3 and i/_Tune.TireCylinders < 2/3 and _Tune.RTireCompound == 3 then
		WFriction(rCyl,(_Tune.RTireFriction+(_Tune.RTireFriction-.1))/2)
		rCyl.Name = rCyl.Name.."M"
	elseif i/_Tune.TireCylinders >= 2/3 or (i/_Tune.TireCylinders >= 1/2 and _Tune.RTireCompound == 2) or _Tune.RTireCompound == 1 then
		WFriction(rCyl,_Tune.RTireFriction)
		rCyl.Name = rCyl.Name.."H"
	end
	
	wait()
end

fWheel.CanCollide = false
fWheel.Transparency = 1
rWheel.CanCollide = false
rWheel.Transparency = 1


