--[[
Creates a fuel sphere.
--]]

return function(CenterCF,FuelColor,Angle,StartingRadius,EndingRadius,Height,Parent)
	local ContainedFuel = FUEL_AMOUNT
	
	--Create the sphere.
	local FuelSphere = Instance.new("Part")
	FuelSphere.Material = "Neon"
	FuelSphere.BrickColor = FuelColor
	FuelSphere.Shape = "Ball"
	FuelSphere.Size = Vector3.new(FUEL_DIAMETER,FUEL_DIAMETER,FUEL_DIAMETER)
	FuelSphere.CustomPhysicalProperties = PhysicalProperties.new(0.7,0,0)
	FuelSphere.TopSurface = "Smooth"
	FuelSphere.BottomSurface = "Smooth"
	FuelSphere.Parent = Parent
	
	--Determine and set the CFrames.
	local HeightCenterCF = CenterCF * CFrame.new(0,Height + (FUEL_DIAMETER/2),0)
	local LandedCF = HeightCenterCF * CFrame.Angles(0,Angle,0) * CFrame.new(0,0,StartingRadius)
	local StartCF = LandedCF * CFrame.new(0,FUEL_START_HEIGHT_OFFSET,FUEL_START_RADIUS_OFFSET)
	FuelSphere.CFrame = StartCF
	
	--Create the BodyVelocity.
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(math.huge,0,math.huge)
	BodyVelocity.Velocity = -StartCF.LookVector * FUEL_MOVEMENT_SPEED
	BodyVelocity.Parent = FuelSphere
	
	spawn(function()
		--Remove the body velocity when the fuel has reached the end.
		while FuelSphere.Parent do
			--Calculate the distance.
			local DeltaX = FuelSphere.Position.X - HeightCenterCF.X
			local DeltaZ = FuelSphere.Position.Z - HeightCenterCF.Z
			local Distance = ((DeltaX ^ 2) + (DeltaZ ^ 2)) ^ 0.5
			
			--If the distance is greater than the ending radius, remove the BodyVelocity and break the loop.
			if Distance > EndingRadius then
				BodyVelocity:Destroy()
				break
			end
			wait()
		end
		
		--Destroy the fuel after 10 seconds if it still exists.
		delay(10,function()
			if FuelSphere.Parent then
				FuelSphere:Destroy()
			end
		end)
		
		--Wait for the fuel to go below the platform.
		while FuelSphere.Parent do
			local DeltaY = math.abs(FuelSphere.Position.Y - HeightCenterCF.Y)
			if DeltaY > 8 then
				break
			end
			wait()
		end
		
		--Set the velocity inward.
		if FuelSphere.Parent and FALLING_INWARD_VELOCITY ~= 0 then
			FuelSphere.Velocity = StartCF.LookVector * FALLING_INWARD_VELOCITY
		end
	end)

	--Create the fuel object.
	local FuelObject = {}
	
	--[[
	Destroys the fuel object.
	--]]
	function FuelObject:Destroy()
		FuelSphere:Destroy()
	end
	
	--[[
	Removes fuel from the sphere.
	--]]
	function FuelObject:RemoveFuel(Amount)
		ContainedFuel = ContainedFuel - Amount
		
		--Update the size.
		local NewDiameter = FUEL_DIAMETER * (ContainedFuel/FUEL_AMOUNT)
		FuelSphere.Size = Vector3.new(NewDiameter,NewDiameter,NewDiameter)
		
		--Destroy the fuel if it is out.
		if ContainedFuel <= 0 then
			self:Destroy()
		end
	end
	
	--[[
	Returns the remaining fuel.
	--]]
	function FuelObject:GetRemainingFuel()
		return ContainedFuel
	end
	
	--[[
	Returns the sphere.
	--]]
	function FuelObject:GetPart()
		return FuelSphere
	end
	
	--Return the fuel object.
	return FuelObject
end
