Basically, I’m making a terrain generation system in my game and I want to generate trees using noise, and they will have a 25% chance of generating based on the seed.
Example:
The current map seed is 12345.
A point on the grid, (40,20), will generate a tree because its position on the perlin noise map is bigger than 0.
if math.noise(x,y,Seed) > 0 then
-- clone tree model and put it on the grid position
end
However, I want this tree to have a 25% chance of generating, and I want it to be based on the seed we have, so every time the map generates using the same seed, the same tree will be placed.
if math.noise(x,y,Seed) > 0 and Chance(0,100,Seed) =< 25 then
-- clone tree model and put it on the grid position
end
Is there a way to make it work? Is it even possible on Roblox?
I’m fairly new to the whole procedural generation thing, so any advice would come handy.
EDIT: Anyway, unless that function has a bug then you shouldn’t have to do anything special, it should still generate the same tree pattern every time with the same seed.
Ah, I don’t mean generating a tree, I mean I want to pick a point on the map using perlin noise and then have a predictable chance which will determine if the tree will be placed.
Like, imagine that the current point’s value on the Perlin noise map is greater than 0.
Now a number between 0 to 100 will generate, but it will always be the same number with that seed.
Ohh, sorry I was tired lol
Well the tree placement is exactly like how I want it, so the Perlin noise isn’t the problem here.
The thing is that I want the trees to have 25% chance of generating, but it will always be the same if the seed is repeated.
If you want it to generate the same number at the same position you need to combine the seed with the position. In other words just use math.noise() again, but this time multiply the x and y by some amount. So that the “size” of the gradient is way smaller.
Yep, this seems to work, but just asking, is there any way to make it work not using Perlin noise? I mean like a function or something.
If not then I’ll just mark your reply as solved
function chance(min, max, seed, x, y)
return Random.new(seed + x + y):NextNumber(min, max)
end
This will be more performant than perlin noise, but it might not evenly spread out the trees. You have to just play around with it to get it to somewhere you like.
For the “perlin” noise I just added regular noise a couple of times, then added a slight blur. (but I should’ve just used an online perlin noise generator)
For combining the noise I first used the magic wand to select everything that is white or similar enough. Then switch to the other noise layer, copy and paste onto a new layer. Then use the magic wand again, this time just fill the selection with white on a new layer, and the background with black.