local function z()local z={}for j,I in pairs(constraints:GetChildren())do if I:IsA("\067\121\108\105\110\100\114\105\099\097\108\067\111\110\115\116\114\097\105\110\116")then table.insert(z,I)end end return z end local function j(z)local j={}local I=PackagedVehicle:FindFirstChild("\084\114\097\105\108\101\114")local function Z(I)local Z="\083\116\114\117\116\083\112\114\105\110\103"local O="\083\116\114\117\116\083\112\114\105\110\103\070"local U="\084\111\114\115\105\111\110\066\097\114\083\112\114\105\110\103"for I,Y in pairs(I)do if Y:IsA("\083\112\114\105\110\103\067\111\110\115\116\114\097\105\110\116")then if z=="\083\116\114\117\116\070\114\111\110\116"then if string.find(Y.Name,O)then table.insert(j,Y)end elseif z=="\083\116\114\117\116\082\101\097\114"then if not string.find(Y.Name,O)and string.find(Y.Name,Z)then table.insert(j,Y)end elseif z=="\084\111\114\115\105\111\110\066\097\114"then if string.find(Y.Name,U)then table.insert(j,Y)end end end end end Z(constraints:GetChildren())if I then Z(I.Constraints:GetChildren())end return j end local function I(z)return z.Attachment1.WorldAxis:Dot(z.Attachment1.Parent.RotVelocity)end local function Z(z,j,I)z.Stiffness=j z.Damping=I end local function O(z)for j,I in pairs(Motors)do I.MotorMaxTorque=z end end local function U(z,j,I)for Z,O in pairs(Motors)do if VehicleParameters.MaxSpeed==0 then O.MotorMaxTorque=0 else local Z=VehicleParameters.MaxSpeed if I<0 and j<0 then Z=VehicleParameters.ReverseSpeed end local U=math.abs(Chassis.driverSeat.Velocity.Magnitude/Z)O.MotorMaxTorque=math.exp((-3*U)*U)*z end end end local function Y(z)for j,I in pairs(Motors)do I.MotorMaxAngularAcceleration=z end end
--[[ Private Functions ]]
--
local function getVehicleMotors()
	local motors = {}
	for _, c in pairs(constraints:GetChildren()) do
		if c:IsA("CylindricalConstraint") then
			table.insert(motors, c)
		end
	end
	return motors
end

local function getSprings(springType)
	local springs = {}
	local trailer = PackagedVehicle:FindFirstChild("Trailer")

	local function search(children)
		local searchStrutSpring = "StrutSpring"
		local searchFrontSpring = "StrutSpringF"
		local searchTorsionSpring = "TorsionBarSpring"
		for _, c in pairs(children) do
			if c:IsA("SpringConstraint") then
				if springType == "StrutFront" then
					if string.find(c.Name, searchFrontSpring) then
						table.insert(springs, c)
					end
				elseif springType == "StrutRear" then
					if (not string.find(c.Name, searchFrontSpring)) and string.find(c.Name, searchStrutSpring) then
						table.insert(springs, c) -- we have option of Mid and Rear for these
					end
				elseif springType == "TorsionBar" then
					if string.find(c.Name, searchTorsionSpring) then
						table.insert(springs, c)
					end
				end
			end
		end
	end

	search(constraints:GetChildren())
	if trailer then
		search(trailer.Constraints:GetChildren())
	end

	return springs
end

local function getMotorVelocity(motor)
	return motor.Attachment1.WorldAxis:Dot(motor.Attachment1.Parent.RotVelocity)
end

local function adjustSpring(spring, stiffness, damping)
	spring.Stiffness = stiffness
	spring.Damping = damping
end

local function setMotorTorque(torque)
	for _, motor in pairs(Motors) do
		motor.MotorMaxTorque = torque
	end
end

local function setMotorTorqueDamped(torque, velocityDirection, accelDirection)
	for _, motor in pairs(Motors) do
		if VehicleParameters.MaxSpeed == 0 then
			motor.MotorMaxTorque = 0
		else
			local maxSpeed = VehicleParameters.MaxSpeed
			if accelDirection < 0 and velocityDirection < 0 then
				maxSpeed = VehicleParameters.ReverseSpeed
			end

			local r = math.abs(Chassis.driverSeat.Velocity.Magnitude / maxSpeed)
			motor.MotorMaxTorque = math.exp(-3 * r * r) * torque
		end
	end
end

local function setMotorMaxAcceleration(acceleration)
	for _, motor in pairs(Motors) do
		motor.MotorMaxAngularAcceleration = acceleration
	end
end
