function RPM()if _CGear==0 then _ClutchOn=false end local Z=_Tune.IdleRPM if not _IsOn then Z=0 _CGear=0 _ClutchOn=false _GThrot=_Tune.IdleThrottle/100 end local Q=0 for Z,A in pairs(Drive)do if A.RotVelocity.Magnitude>Q then Q=A.RotVelocity.Magnitude end end if _ClutchOn then local A=math.max(math.min((Q*_Tune.Ratios[_CGear+2])*fFDr,_Tune.Redline+100),Z)local F=math.min(math.abs(A-_RPM)/_Tune.ClutchTol,.9)_RPM=_RPM*F+A*(1-F)else if _GThrot-_Tune.IdleThrottle/100>0 then if _RPM>_Tune.Redline then _RPM=_RPM-_Tune.RevBounce*2 else _RPM=math.min(_RPM+_Tune.RevAccel*_GThrot,_Tune.Redline+100)end else _RPM=math.max(_RPM-_Tune.RevDecay,Z)end end _spLimit=(_Tune.Redline+100)/(fFDr*_Tune.Ratios[_CGear+2])if _RPM>_Tune.Redline then if _CGear<#_Tune.Ratios-2 then _RPM=_RPM-_Tune.RevBounce else _RPM=_RPM-_Tune.RevBounce*.5 end end end
--Update RPM
function RPM()
	--Neutral Gear
	if _CGear == 0 then
		_ClutchOn = false
	end

	--Car Is Off
	local revMin = _Tune.IdleRPM
	if not _IsOn then
		revMin = 0
		_CGear = 0
		_ClutchOn = false
		_GThrot = _Tune.IdleThrottle / 100
	end

	--Determine RPM
	local maxSpin = 0
	for i, v in pairs(Drive) do
		if v.RotVelocity.Magnitude > maxSpin then
			maxSpin = v.RotVelocity.Magnitude
		end
	end
	if _ClutchOn then
		local aRPM = math.max(math.min(maxSpin * _Tune.Ratios[_CGear + 2] * fFDr, _Tune.Redline + 100), revMin)
		local clutchP = math.min(math.abs(aRPM - _RPM) / _Tune.ClutchTol, 0.9)
		_RPM = _RPM * clutchP + aRPM * (1 - clutchP)
	else
		if _GThrot - (_Tune.IdleThrottle / 100) > 0 then
			if _RPM > _Tune.Redline then
				_RPM = _RPM - _Tune.RevBounce * 2
			else
				_RPM = math.min(_RPM + _Tune.RevAccel * _GThrot, _Tune.Redline + 100)
			end
		else
			_RPM = math.max(_RPM - _Tune.RevDecay, revMin)
		end
	end

	--Rev Limiter
	_spLimit = (_Tune.Redline + 100) / (fFDr * _Tune.Ratios[_CGear + 2])
	if _RPM > _Tune.Redline then
		if _CGear < #_Tune.Ratios - 2 then
			_RPM = _RPM - _Tune.RevBounce
		else
			_RPM = _RPM - _Tune.RevBounce * 0.5
		end
	end
end
