--[[Chassis Assembly]]

		--Create Steering Axle
		local arm=Instance.new("Part",v)
		arm.Name="Arm"
		arm.Anchored=true
		arm.CanCollide=false
		arm.FormFactor=Enum.FormFactor.Custom
		arm.Size=Vector3.new(_Tune.AxleSize,_Tune.AxleSize,_Tune.AxleSize)
		arm.CFrame=(v.CFrame*CFrame.new(0,_Tune.StAxisOffset,0))*CFrame.Angles(-math.pi/2,-math.pi/2,0)
		arm.CustomPhysicalProperties = PhysicalProperties.new(_Tune.AxleDensity,0,0,100,100)
		arm.TopSurface=Enum.SurfaceType.Smooth
		arm.BottomSurface=Enum.SurfaceType.Smooth
		arm.Transparency=1
			
		--Create Wheel Spindle
		local base=arm:Clone()
		base.Parent=v
		base.Name="Base"
		base.CFrame=base.CFrame*CFrame.new(0,_Tune.AxleSize,0)
		base.BottomSurface=Enum.SurfaceType.Hinge
		
		--Create Steering Anchor
		local axle=arm:Clone()
		axle.Parent=v
		axle.Name="Axle"
		axle.CFrame=CFrame.new(v.Position-((v.CFrame*CFrame.Angles(math.pi/2,0,0)).lookVector*((v.Size.x/2)+(axle.Size.x/2))),v.Position)*CFrame.Angles(0,math.pi,0)
		axle.BackSurface=Enum.SurfaceType.Hinge
		
		--Create Powered Axle (LuaInt)
		local axlep=arm:Clone()
		axlep.Parent=v
		axlep.Name='AxleP'
		axlep.CFrame=v.CFrame
		MakeWeld(axlep,axle)
		
		if v.Name=="F" or v.Name=="R" then
			local axle2=arm:Clone()
			axle2.Parent=v
			axle2.Name="Axle"
			axle2.CFrame=CFrame.new(v.Position+((v.CFrame*CFrame.Angles(math.pi/2,0,0)).lookVector*((v.Size.x/2)+(axle2.Size.x/2))),v.Position)*CFrame.Angles(0,math.pi,0)
			axle2.BackSurface=Enum.SurfaceType.Hinge
			MakeWeld(arm,axle2)
		end
		
		--Create Suspension
		if _Tune.SuspensionEnabled==true then
			local SuspensionGeometry=v:FindFirstChild("SuspensionGeometry")
			if SuspensionGeometry then
			
				local WeldModel=SuspensionGeometry:FindFirstChild('Weld')
				if WeldModel then
					ModelWeld(WeldModel,car.DriveSeat)
				end
				MakeWeld(SuspensionGeometry.SpringTop,car.DriveSeat)
				MakeWeld(SuspensionGeometry.Hub,base)
				
				local susparts=SuspensionGeometry:GetDescendants()
				for _,p in pairs(susparts) do
				if p:IsA('Part') then
						if _Tune.CustomSuspensionDensity~=0 then
							p.CustomPhysicalProperties=PhysicalProperties.new(_Tune.CustomSuspensionDensity,0,0,0,0)
						else
							p.CustomPhysicalProperties=PhysicalProperties.new(_Tune.CustomSuspensionDensity,0,0,0,0)
							p.Massless=true
						end
					end
				end
			
				if _Tune.SusVisible==true then
					for _,p in pairs(susparts) do
						if p:IsA('Part') then
							p.Transparency=.5
						elseif p:IsA("SpringConstraint") or p:IsA("HingeConstraint") or p:IsA("BallSocketConstraint") then
							p.Visible=true
						end
					end
				else
					for _,p in pairs(susparts) do
						if p:IsA('Part') then
							p.Transparency=1
						elseif p:IsA("SpringConstraint") or p:IsA("HingeConstraint") or p:IsA("BallSocketConstraint") then
							p.Visible=false
						end
					end
				end
			
				local g = Instance.new("BodyGyro",SuspensionGeometry:FindFirstChild('SpringBottom'))
				g.Name = "Stabilizer"
				g.MaxTorque = Vector3.new(0,0,1)
				g.P = 0
				
				sp=SuspensionGeometry:FindFirstChildOfClass('SpringConstraint')
				sp.LimitsEnabled = true
				sp.Visible=_Tune.SusVisible
				sp.Radius=_Tune.SusRadius
				sp.Thickness=_Tune.SusThickness
				sp.Color=BrickColor.new(_Tune.SusColor)
				sp.Coils=_Tune.SusCoilCount

				if v.Name == "FL" or v.Name=="FR" or v.Name =="F" then
					g.D = _Tune.FGyroDampening
					sp.Damping = _Tune.FSusDamping
					sp.Stiffness = _Tune.FSusStiffness
					sp.FreeLength = _Tune.FSusLength+_Tune.FPreCompress
					sp.MaxLength = _Tune.FSusLength+_Tune.FExtensionLim
					sp.MinLength = _Tune.FSusLength-_Tune.FCompressLim
				else
					g.D = _Tune.RGyroDampening
					sp.Damping = _Tune.RSusDamping
					sp.Stiffness = _Tune.RSusStiffness
					sp.FreeLength = _Tune.RSusLength+_Tune.RPreCompress
					sp.MaxLength = _Tune.RSusLength+_Tune.RExtensionLim
					sp.MinLength = _Tune.RSusLength-_Tune.RCompressLim
				end
			
				v.Massless=false
			else
				local sa=arm:Clone()
				sa.Parent=v
				sa.Name="#SA"
				if v.Name == "FL" or v.Name=="FR" or v.Name =="F" then
					local aOff = _Tune.FAnchorOffset
					sa.CFrame=v.CFrame*CFrame.new(_Tune.AxleSize/2,-fDistX,-fDistY)*CFrame.new(aOff[3],aOff[1],-aOff[2])*CFrame.Angles(-math.pi/2,-math.pi/2,0)
				else
					local aOff = _Tune.RAnchorOffset
					sa.CFrame=v.CFrame*CFrame.new(_Tune.AxleSize/2,-rDistX,-rDistY)*CFrame.new(aOff[3],aOff[1],-aOff[2])*CFrame.Angles(-math.pi/2,-math.pi/2,0)
				end

				local sb=sa:Clone()
				sb.Parent=v
				sb.Name="#SB"
				sb.CFrame=sa.CFrame*CFrame.new(0,0,_Tune.AxleSize)

				sb.FrontSurface=Enum.SurfaceType.Hinge	

				local g = Instance.new("BodyGyro",sb)
				g.Name = "Stabilizer"
				g.MaxTorque = Vector3.new(0,0,1)
				g.P = 0

				local sf1 = Instance.new("Attachment",sa)
				sf1.Name = "SAtt"

				local sf2 = sf1:Clone()
				sf2.Parent = sb

				--(Avxnturador) adds spring offset
				if v.Name == "FL" or v.Name == "FR" or v.Name == "F" then
					local aOff = _Tune.FSpringOffset
					if v.Name == "FL" then
						sf1.Position = Vector3.new(fDistX-fSLX+aOff[1],-fDistY+fSLY+aOff[2],_Tune.AxleSize/2+aOff[3])
						sf2.Position = Vector3.new(fDistX+aOff[1],-fDistY+aOff[2],-_Tune.AxleSize/2+aOff[3])
					else
						sf1.Position = Vector3.new(fDistX-fSLX+aOff[1],-fDistY+fSLY+aOff[2],_Tune.AxleSize/2-aOff[3])
						sf2.Position = Vector3.new(fDistX+aOff[1],-fDistY+aOff[2],-_Tune.AxleSize/2-aOff[3])
					end
				elseif v.Name == "RL" or v.Name=="RR" or v.Name == "R" then
					local aOff = _Tune.RSpringOffset
					if v.Name == "RL" then
						sf1.Position = Vector3.new(rDistX-rSLX+aOff[1],-rDistY+rSLY+aOff[2],_Tune.AxleSize/2+aOff[3])
						sf2.Position = Vector3.new(rDistX+aOff[1],-rDistY+aOff[2],-_Tune.AxleSize/2+aOff[3])
					else
						sf1.Position = Vector3.new(rDistX-rSLX+aOff[1],-rDistY+rSLY+aOff[2],_Tune.AxleSize/2-aOff[3])
						sf2.Position = Vector3.new(rDistX+aOff[1],-rDistY+aOff[2],-_Tune.AxleSize/2-aOff[3])
					end
				end

				sb:MakeJoints()
				--(LuaInt) there was axle:makejoints here I believe, but the new powered axle manually welds itself so I ditched it

				local sp = Instance.new("SpringConstraint",v)
				sp.Name = "Spring"
				sp.Attachment0 = sf1
				sp.Attachment1 = sf2
				sp.LimitsEnabled = true

				sp.Visible=_Tune.SusVisible
				sp.Radius=_Tune.SusRadius
				sp.Thickness=_Tune.SusThickness
				sp.Color=BrickColor.new(_Tune.SusColor)
				sp.Coils=_Tune.SusCoilCount

				if v.Name == "FL" or v.Name=="FR" or v.Name =="F" then
					g.D = _Tune.FGyroDampening
					sp.Damping = _Tune.FSusDamping
					sp.Stiffness = _Tune.FSusStiffness
					sp.FreeLength = _Tune.FSusLength+_Tune.FPreCompress
					sp.MaxLength = _Tune.FSusLength+_Tune.FExtensionLim
					sp.MinLength = _Tune.FSusLength-_Tune.FCompressLim
				else
					g.D = _Tune.RGyroDampening
					sp.Damping = _Tune.RSusDamping
					sp.Stiffness = _Tune.RSusStiffness
					sp.FreeLength = _Tune.RSusLength+_Tune.RPreCompress
					sp.MaxLength = _Tune.RSusLength+_Tune.RExtensionLim
					sp.MinLength = _Tune.RSusLength-_Tune.RCompressLim
				end

				MakeWeld(car.DriveSeat,sa)
				MakeWeld(sb,base)
			end
		else
			MakeWeld(car.DriveSeat,base)
		end
		
		--Lock Rear Steering Axle
		if _Tune.FWSteer=='Static' or _Tune.FWSteer=='Speed' or _Tune.FWSteer=='Both' then
		else
			if v.Name == "RL" or v.Name == "RR" or v.Name=="R" then
				MakeWeld(base,axle)
			end
		end
		
		--Weld Assembly
		if v.Parent.Name == "RL" or v.Parent.Name == "RR" or v.Name=="R" then
			MakeWeld(car.DriveSeat,arm)
		end
		
		MakeWeld(arm,axle)
		
		arm:MakeJoints()
	
		--Weld Miscelaneous Parts
		if v:FindFirstChild("SuspensionFixed")~=nil then
			ModelWeld(v.SuspensionFixed,car.DriveSeat)
		end
		if v:FindFirstChild("WheelFixed")~=nil then
			ModelWeld(v.WheelFixed,axle)
		end
		if v:FindFirstChild("Fixed")~=nil then
			ModelWeld(v.Fixed,arm)
		end
		
		--Weld Wheel Parts
		if v:FindFirstChild("Parts")~=nil then
			ModelWeld(v.Parts,v)
		end
		
		--Add Steering Gyro
		if v:FindFirstChild("Steer") then
			v:FindFirstChild("Steer"):Destroy()
		end
	
		if v.Name=='FR' or v.Name=='FL' or v.Name=='F' then
			local steer=Instance.new("BodyGyro",arm)
			steer.Name="Steer"
			steer.P=_Tune.SteerP
			steer.D=_Tune.SteerD
			steer.MaxTorque=Vector3.new(0,_Tune.SteerMaxTorque,0)
			steer.cframe=v.CFrame*CFrame.Angles(0,-math.pi/2,0)
		else
			if (_Tune.FWSteer=='Static' or _Tune.FWSteer=='Speed' or _Tune.FWSteer=='Both') then
				local steer=Instance.new("BodyGyro",arm)
				steer.Name="Steer"
				if _Tune.RSteerP~=nil and _Tune.RSteerD~=nil and _Tune.RSteerMaxTorque~=nil then
					steer.P=_Tune.RSteerP
					steer.D=_Tune.RSteerD
					steer.MaxTorque=Vector3.new(0,_Tune.RSteerMaxTorque,0)
				else
					steer.P=_Tune.SteerP
					steer.D=_Tune.SteerD
					steer.MaxTorque=Vector3.new(0,_Tune.SteerMaxTorque,0)
				end
				steer.cframe=v.CFrame*CFrame.Angles(0,-math.pi/2,0)
			end
		end
		
		--Add Stabilization Gyro
		local gyro=Instance.new("BodyGyro",v)
		gyro.Name="Stabilizer"
		gyro.MaxTorque=Vector3.new(1,0,1)
		gyro.P=0
		if v.Name=="FL" or v.Name=="FR"  or v.Name=="F" then
			gyro.D=_Tune.FGyroDamp
		else
			gyro.D=_Tune.RGyroDamp
		end
		
		--Add Motors (LuaInt)
		local AV=Instance.new("HingeConstraint",v)
		AV.ActuatorType='Motor'
		AV.Attachment0=Instance.new("Attachment",v.AxleP)
		v.AxleP.Attachment.Name='AA'
		AV.Attachment1=Instance.new("Attachment",v)
		v.Attachment.Name='AB'
		AV.Name="#AV"
		AV.AngularVelocity=0
		AV.MotorMaxTorque=0
		
		local BV=Instance.new("HingeConstraint",v)
		BV.ActuatorType='Motor'
		BV.Attachment0=Instance.new("Attachment",v.AxleP)
		v.AxleP.Attachment.Name='BA'
		BV.Attachment1=Instance.new("Attachment",v)
		v.Attachment.Name='BB'
		BV.Name="#BV"
		BV.AngularVelocity=0
		BV.MotorMaxTorque=_Tune.PBrakeForce
		
		for _,c in pairs(v:GetDescendants()) do
			if c.ClassName=='Attachment' and c.Name~='SAtt' then
				if c.Parent.Name=='FL' or c.Parent.Name=='RL' or c.Parent.Parent.Name=='FL' or c.Parent.Parent.Name=='RL' then c.Orientation=Vector3.new(0,0,90) end
				if c.Parent.Name=='F' or c.Parent.Name=='R' or c.Parent.Parent.Name=='F' or c.Parent.Parent.Name=='R' 
				or c.Parent.Name=='FR' or c.Parent.Name=='RR' or c.Parent.Parent.Name=='FR' or c.Parent.Parent.Name=='RR' then c.Orientation=Vector3.new(180,0,90) end
			end
		end
	end


