Random Map Generation

Hey guys, so I am making a find the button type of game, but I am sure it is going to be SUPER cool, because I will be adding a lot of gamemodes, so the game has potential

My problem is… since I want it to be a really cool game, I need to make a map randomly generate with objects I decide need to be in that map, plus, generate the button at a random place in this map every single time.

I searched for at least 5 hours on youtube and on the dev hub, but haven’t find anything.
The game will have like 5 stages every time you start the game (to make it look really cool)

3 Likes

You can use math.random to choose a random map.

He want to make a random map generation, not random map chooser.

Oh, idk then, I don’t know how to script.

1 Like

This is very difficult to do, even if you are a professional programmer, because these are not blocks, like in minecraft, where you can always find out if one block overlaps another, these are objects of different shapes. Of course, you can determine if one object overlaps another, but there is always a chance that a button will appear in a rock, for example or even in air. Making such a random map is very difficult, so you better create a large number of maps with your hands.

You can place invisible parts on all of your maps, and in the script, pick a random one and place a button on its position, so you will always know that button will appear correctly. It will not be a random generation, but it is the best way to do it.

Hey, thanks a lot for all of that, but do you think I can make different parts of the map, for example bridges and water in the map, then make it so that those parts of the map spawn randomly? then add places where the button can spawn (like 200 places manually?)

Yes you can do that, but when you place a bridge or other objects make sure there are no positions for button.

1 Like

Then what should I make it for the button?

What do you mean‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎?

You said that it should not be a position, I did not understand what you really meant, any vids or examples by you that could help me?

I never said that it shouldn’t be a position. If I did then quote it.

You said no position for button I mean

About what post are you talking?

Oh I just realized. I meant make sure to check if you didn’t occuped that position for button when placing other objects.

you can use the script that i made!
You can create an automatic map with the numbers you give, spawn possibilities, spawn location with a script!
this is how you can use it!

local partcount = 100 -- How much part this map will have...
local mapgenerateplace = Vector3.new(0,0,0) -- Where the map generates itself...
local partspawn = 10 -- Possibility of parts.Position
-- Dont touch below if you dont know...
local wk,pl = game:GetService("Workspace"),game:GetService("Players")
function spawnmap()
	for i = 1,partcount,1 do
		local newpart = Instance.new("Part",wk)
		newpart.Position,newpart.Anchored = Vector3.new(mapgenerateplace.X + math.random(1,partspawn),mapgenerateplace.Y + math.random(1,partspawn),mapgenerateplace.Z + math.random(1,partspawn)),true
	end
end
-- type 
spawnmap()
-- whenever you want to spawn map :)

You should use math.noise inside your script

Here is an example of math.noise with your script:
image
Script:

local mapgenerateplace = Vector3.new(0,0,0) -- Where the map generates itself...
local partspawn = 10 -- Possibility of parts.Position
local Length = 80
-- Dont touch below if you dont know...
local wk,pl = game:GetService("Workspace"),game:GetService("Players")
function spawnmap()
	local RandomSeed = math.random(100,10000000)
	for XAxis = 1, Length do
		for ZAxis = 1, Length do
			local PosHeight = math.noise(RandomSeed, XAxis / 50, ZAxis / 50) * 40
			local newpart = Instance.new("Part",wk)
			newpart.Color = Color3.fromRGB(7, 145, 0)
			newpart.Material = Enum.Material.SmoothPlastic
			newpart.Anchored = true
			newpart.Position = newpart.Position + Vector3.new(XAxis, PosHeight, ZAxis)
		end	
	end
end
-- type 
spawnmap()
-- whenever you want to spawn map :)
3 Likes

thats an advanced one with my script… thank you :slight_smile:

Thanks a lot for what all of you guys did to help me!