function getSmoothRotation(y)local u=y[1]local l=y[2]local D=tankStats.GunDepression.Value if math.abs(u)>D then u=D*sign(u)end local M=u-currentElev if math.abs(M)<.01 then currentElev=u else currentElev=currentElev+.01*sign(M)end local t=l-currentRot if t>math.pi then t=t-2*math.pi elseif t<-math.pi then t=t+2*math.pi end local o=tankStats.TurretSpeed.Value if math.abs(t)<o then currentRot=l else currentRot=currentRot+o*sign(t)end local K={}K[1]=u K[2]=l return K end
-- Using the desired target rotation and elevation, determine where the gun should point right now (smoothly turn)
function getSmoothRotation(rotations)
	local targElev = rotations[1]
	local targRot = rotations[2]

	local maxGunDepression = tankStats.GunDepression.Value

	-- Restrict the height of travel of the gun
	if math.abs(targElev) > maxGunDepression then
		targElev = maxGunDepression * sign(targElev)
	end

	-- Once target angles are set, slowly turn turret towards them
	-- Elevation
	local elevDiff = targElev - currentElev
	if math.abs(elevDiff) < 0.01 then -- If they're close
		currentElev = targElev
	else -- Move towards it
		currentElev = currentElev + 0.01 * sign(elevDiff)
	end

	-- Rotation
	local rotDiff = targRot - currentRot

	if rotDiff > math.pi then
		rotDiff = rotDiff - 2 * math.pi
	elseif rotDiff < -math.pi then
		rotDiff = rotDiff + 2 * math.pi
	end

	local turretSpeed = tankStats.TurretSpeed.Value

	if math.abs(rotDiff) < turretSpeed then -- If they're close
		currentRot = targRot
	else -- Move towards it
		currentRot = currentRot + turretSpeed * sign(rotDiff)
	end

	-- Put rotation and elevation into an array
	local rotations = {}
	rotations[1] = targElev
	rotations[2] = targRot

	return rotations
end
