Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Generating Trees/Rocks, etc. on a grid?

I'm making a game like Clash of Clans, and I need somewhere to start on the map generating aspect of it. So basically, I have rocks and trees built, they need to be on a grid (of 5 by 5 bricks). I'm just looking for feedback on how I would generate the items on the grid.

I just need some advice on how'd I would do that, I'm not requesting, don't get me wrong, I just need help on how I could make this, all I need is to know how to generate something on a grid.

No, I don't have any example code, as I said I need somewhere to start.

1 answer

✓ Accepted answer

This is interesting idea as I haven't really seen much of this done on roblox my thinking would be is to make a bunch of 5x5 parts and then store their positions within a table

using

table.insert

and then pick a random position from that table to place a tree at btw if you are moving a model doing

local model = game.Lighting.MODELNAME -- this would be a tree or rock
local table = {} -- create a empty table

local children = workspace:GetChildren()
for i = 1, #children do
	if children[i].Name == node then
    print(i, children[i].Position)
	table.insert(children[i].Position)
	else
end

local chosenposition = table[math.random(1, #table)] -- pick random position from the table
local c = model:Clone() -- copy the model
c.Parent = game.Workspace -- move the copied model to the workspace
c:Move(vector3.new(chosenposition)) -- move the model to the position of the part
table.remove(table, chosenposition)

I think that's roughly how it would work hope it helps :)

4 comments

0

I'd recommend game:GetService("ServerStorage") to deal with hidden storages and such rather than Lighting

0

It all just comes down to preference in the end and what the developer wants with their game but you are right

0

Thank you, this helps a lot.

0

@Du_k no problem glad to help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.