I am trying to make a Minecraft-like game on ROBLOX and I tried to make a generate script for grass. Here is what I tried:
grass = script.Parent.Grass blocks = {grass} grass.Anchored = true for i,v in pairs(blocks) do generatedblocks = Instance.new("Part", Workspace) generatedblocks.Name = "Grass" generatedblocks.Size = grass.Name generatedblocks.Anchored = true generatedblocks.Position = -- I dont know what to put here and the rest. end
To make a straightforward generation you first need to think of what you need. Let's strip down the problem to the base problem: we need to generate a blocky-like landscape. You can later implement biomes and types of blocks.
Reviewing your current code: there are some problems in it.
First of all you are looping over "blocks", a table which only has one member. That means that it will run it's code only once. I wouldn't do that, I would loop over an x and z range (the positions). To chose a block you can always use math.random to get a random block from the list.
Second: you are assigning Size to a Name. Size is a Vector3 and Name is a string. This will always conflict. I take that script.Parent.Grass
is a brick: why not clone it?
The simplest terrain generator will just loop over all x and z positions and will assign a random height to it. You will see that the terrain will be extremely "peaky". If you run the code you will see what I mean. It is better to study random "noise" generators - I would suggest Perlin Noise.
local block = script.Parent.Grass local function GetBlock() return block:Clone() end local function GetSize() return block.Size.z end -- Assing random position ranges local x_min, x_max = -100,100 local z_min, z_max = -100, 100 local y_min, y_max = 1,10 -- this is in block units. for x = x_min, x_max, GetSize() do for z = z_min, z_max, GetSize() do local height = math.random(y_min, y_max) for y = GetSize()/2, GetSize() * (height + 0.5), GetSize() do local block = GetBlock() block.CFrame = CFrame.new(x,y,z) block.Parent = game.Workspace end wait() -- due the amount of recurses; wait, otherwise roblox will crash end end
Well I'm not quite sure what your asking because I know you can generate random terrain but I'm not quite sure about generating Grass Blocks even though it seems simple enough.
Well I could help you with setting the position it would have to be using the code Vector3.new(0,0,0)
and you would have to find a way to keep adding that up evenly, throughout the base plate. You could also use Loop
if that might give you any ideas? Not quite sure how this script would work but it is interesting.
Locked by JesseSong
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?