However, the system makes quite a dent in performance. There are some improvements I think you should take into consideration (there might be more, but this might help):
Try to avoid using while true do if you can because of this.
If this will be used in games, move your code to the client: visuals like these (especially constantly updating CFrame and position for animations) should be on the client so the server doesn’t have to bother computing and replicating any of that.
If you use RunService to replace the loop and you’ve moved it to the client, make use of deltaTime when determining how much to move everything.
Keep it small: if this will be in a game, updating this many parts so often can create a large performance impact so I don’t recommend keeping the grid too big (this is more of a suggestion for those utilizing the system).
Try to cut down on the amount of calculations you are doing each iteration of any loop and take into consideration how you have loops inside loops - you might even need to restructure the system to limit how many total iterations that every loop goes through (with enough work, I’m sure you can figure something out).
Lastly, some quick possible code improvements:
Comment your code for newer developers! Even if you understand what certain parts do, that doesn’t mean somebody else would.
Lines like these var = var + number can be replaced with var += number. Read about that here.
Add some spacing in your code: separate a constant stream of lines with the occasional double new line to visually separate different parts of your code (this is the way I prefer to do it, but it can really be done any way - see below for example).
Code spacing example
Side note: code spacing can also help make room for commenting chunks of your code!
local function GetBlock(Name)
local Block = LevelGrp:FindFirstChild(Name)
if(Block == nil) then
Block = Instance.new("Part",LevelGrp)
Block.Size = Vector3.new(BlockSize,BlockSize,BlockSize)
Block.Material = Enum.Material.SmoothPlastic
Block.BrickColor = BrickColor.Blue()
Block.Anchored = true
Block.CanCollide = true
Block.Name = Name
Block.Transparency = BaseTransparency
local Faces = {"Left","Right","Top","Bottom","Back","Front"}
for i,v in pairs(Faces) do
Block[v.."Surface"] = Enum.SurfaceType.SmoothNoOutlines
end
end
return Block
end
I had made something similar to this in the past and basically I just varied the perlin “density” (the inputs you give the math.noise function) to give it the “illusion” of it moving.
Yes, but the problem is when I do a For Loop to create the bones, the Plane Mesh does not deform. I made a thread about it. But I have still not found a Solution.
I have made something similar to that in the program itself but not in roblox. Basically you need to create its end state in the program then play whats called literally a “Mesh Deform Modifier”. You then set the keyframe state to 1 then move the meshes verticies save the keyframe then u can animate its state in the program. Perhaps what you could do is animate it from 0 to 1 and expand it to the perlin range.
In most simplest terms it is the concept of taking 2 values and mapping them to a range, so say we have 5 and 10 and our “alpha” is at 0.5 (the domain of alpha is 0 to 1). That would mean our alpha would return 7.5. Now we can expand this to 3d by simply interpolating each position component in our vertices.
I basically transposed the lerp function so I could map it to the perlin density range, so if I returned a perlin density of 0.25 that’d be 1 and -0.25 would be 0. I made a module that includes what I used btw however it’s really simple you could make your own by using like mathpapa or some crap then solve for the alpha