Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --//minecraft-style perlin noise based cloud generation written 9/1/22 by zynonical
- --settings
- local size = 300--the size of each individual cloud part, in studs
- local height = 500--the height of the cloud model, in studs on the Y axis. global.\
- local cloudspeed = 25--the speed that each cloudmodel moves. studs per second.
- local chunklength = 25--the square root of the number of clouds parts in a cloud model
- -----------------------------------------------------------------------------------------------
- --
- local tweenservice = game:GetService("TweenService")
- local cloudfolder = Instance.new("Folder",workspace);cloudfolder.Name = "cloudfolder"
- --
- local track = 0
- local function noise()
- track = math.noise(track,0,math.random(2,999)/1000);return track --returns the noise, track is to keep track of the... noise.
- end
- local function get_tween(model,speed,distance) --i find it cleaner and less repetitive to have the tweening done from a function. tweening system could really be improved by roblox
- local info = TweenInfo.new((distance)/speed,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)--distance divided by speed == time
- return tweenservice:Create(model.PrimaryPart,info,{CFrame = CFrame.new(Vector3.new(model.PrimaryPart.Position.X + (distance),height,model.PrimaryPart.Position.Z))})
- end
- local function createcloudchunk() --generates the cloud chunk
- local chunkmodel = Instance.new("Model")
- local root = Instance.new("Part",chunkmodel) --root is for tweening the model.
- for i = 1, chunklength do --rows
- if noise() <= -0.2 then
- local newpart = Instance.new("Part",chunkmodel)-- chunkmodel.Parent is still nil, so the second parameter of Instance.new() is comepletely fine to use
- newpart.Material = Enum.Material.SmoothPlastic;newpart.CanCollide = false;newpart.Anchored = false
- newpart.Size = Vector3.new(size,25,size);newpart.Color = Color3.fromRGB(230,230,230)
- newpart.Position = Vector3.new(0,height,i*size)
- local weld = Instance.new("WeldConstraint");weld.Part0=newpart;weld.Part1=root;weld.Parent=newpart
- end
- for x = 1, chunklength-1 do --columns. --for each cloudpart in the bottom row, create #chunklength-1 number reaching out on the X-axis. results in grid.
- if noise() <= -0.2 then
- local bpart = Instance.new("Part",chunkmodel)
- bpart.Material = Enum.Material.SmoothPlastic;bpart.CanCollide = false;bpart.Anchored = false
- bpart.Size = Vector3.new(size,25,size);bpart.Color = Color3.fromRGB(230,230,230)
- bpart.Position = Vector3.new(x*size,height,i*size)
- local weld = Instance.new("WeldConstraint");weld.Part0=bpart;weld.Part1=root;weld.Parent=bpart
- end
- end
- end
- root.CFrame = chunkmodel:GetBoundingBox();root.Anchored = true;root.Transparency = 1--before i found out about :GetBoundingBox(), there was some really impressive math here
- chunkmodel.PrimaryPart = root;return chunkmodel
- end
- -----------------------------------------LOOP_FUNCTIONS
- local function cloud()
- local e = tick();local chunk1 = createcloudchunk();print(tick()-e) --tick() for testing how fast the cloudchunk generation runs. ~0.0007 seconds is average. pretty good
- --local chunk1 = createcloudchunk() --easily comment in/out to switch from printing tick() in previous line.
- chunk1:PivotTo(CFrame.new(Vector3.new(-(chunklength*size),height,0)))
- chunk1.Parent = cloudfolder
- local tween = get_tween(chunk1,cloudspeed,chunklength*size);tween:Play()
- local listener; listener = tween.Completed:Connect(function() --these listeners all disconnect, so there's no concern for memory leaks
- listener:Disconnect()
- local tween2 = get_tween(chunk1,cloudspeed,(chunklength*size)*2);tween2:Play();cloud()
- local listener2; listener2 = tween2.Completed:Connect(function()
- listener2:Disconnect()
- chunk1:Destroy()
- end)
- end)
- end
- -----------------------------------------
- ------start
- local startingcloud = createcloudchunk()--this is kind of a cheat of my own code, but it's easier than rewriting the createcloudchunk() function. and this obviously only runs once
- startingcloud:PivotTo(CFrame.new(Vector3.new(0,height,0)))
- startingcloud.Parent = cloudfolder
- local tween = get_tween(startingcloud,cloudspeed,chunklength*size);tween:Play()
- local listen;listen = tween.Completed:Connect(function()
- listen:Disconnect();startingcloud:Destroy()
- end)
- cloud()
- ------
- --[[
- super performant and easily customizable. 0.0007 seconds to generate a cloudchunk/model. runs great on even the lowest end mobile phones, and looks beautiful on lvl10 graphics (imo)
- ]]
Advertisement