Custom cloud generator!

So today I saw Sebastian Lague’s new video on geography and stuff, and I got a ton of ideas. One of them was to recreate the clouds I saw in the video, with a few changes to fit my style, and well, I’d say I did a pretty good job.

Image:

FYI, the clouds weren’t animated to I just took a screen shot.

Here is the code

local Cloud = {}

function Cloud.Spawn(position: Vector3, baseSize: Vector3, containerSize: Vector3, minSize: number, maxSize: number, density: number, model: boolean, modelName: string?, parent: Instance)
	local cloud = {  }
	local cloudModel

	local base = Instance.new("Part")

	local sphereMesh = Instance.new("SpecialMesh")
	sphereMesh.MeshType = Enum.MeshType.Sphere
	sphereMesh.Parent = base

	base.Anchored = true
	base.Color = Color3.fromRGB(255, 255, 255)
	base.Size = baseSize
	base.Position = position
	base.CanCollide = false
	base.TopSurface = Enum.SurfaceType.SmoothNoOutlines
	base.BottomSurface = Enum.SurfaceType.SmoothNoOutlines

	cloud[#cloud + 1] = base

	local container = Instance.new("Part")
	container.Transparency = 0.75
	container.Anchored = true
	container.CanCollide = false
	container.Position = base.Position
	container.Size = containerSize

	for i = 0, density do
		local cloudPart = base:Clone()
		sphereMesh:Clone().Parent = cloudPart

		cloud[#cloud + 1] = cloudPart
	end

	if model then
		cloudModel = Instance.new("Model")
		cloudModel.Name = modelName
	end

	for i, part in pairs(cloud) do
		part.CFrame = container.CFrame * CFrame.new(
			Random.new():NextNumber(-container.Size.X/2, container.Size.X/2), 
			Random.new():NextNumber(-container.Size.Y/2, container.Size.Y/2), 
			Random.new():NextNumber(-container.Size.Z/2, container.Size.Z/2))

		part.Transparency = math.abs(math.sin(i))

		local size = Random.new():NextNumber(minSize, maxSize)
		part.Size = Vector3.new(size, size, size)

		if model then
			part.Parent = cloudModel
			cloudModel.Parent = parent
		else 
			part.Parent = parent
		end
	end

	container:Destroy()

	if model then
		return cloudModel
	else 
		return cloud
	end
end

return Cloud

Example of using it:

local Cloud = require(game.ReplicatedStorage.Cloud)

Cloud.Spawn(Vector3.new(20, 50, 30), Vector3.new(5, 5, 5), Vector3.new(15, 15, 50), 5, 10, 100, true, "Cloud", workspace)
Cloud.Spawn(Vector3.new(100, 100, 100), Vector3.new(10, 10, 10), Vector3.new(50, 25, 75), 10, 25, 75, true, "Cloud2", workspace)
Cloud.Spawn(Vector3.new(50, 50, 50), Vector3.new(1, 1, 1), Vector3.new(15, 15, 15), 1, 5, 50, true, "Cloud3", workspace)

The reason why this isn’t a resource is because Roblox already made clouds, and because other people made way better clouds that this, but it was a nice experience. The thing I’m the most proud of is using math.sin() to make seemingly random transparent cloud parts that look smooth.

If you have any feedback, please leave them down in the replies below!

EDIT: You can use the cloud generator if you want.

EDIT 2: I replaced the math.random() inside the section of the code to generate cloud parts inside the container to Random.new():NextNumber() so it can use decimals.

6 Likes

This is really cool. Even with ROBLOX adding built-in clouds, this is still something we can all use and play around with.

2 Likes