Map generation problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
tigerclaw
Prole
Posts: 1
Joined: Thu Aug 18, 2016 5:36 pm

Map generation problem

Post by tigerclaw »

I am trying to generate a map using Simplex\Perlin noise. Debugging with the print function, I have discovered that love.math.noise is producing the same number for every x,y, and "seed" combination. Here is a snippet of the code:

Code: Select all

function gen_map()
	seed = love.math.random(0,10000)

	for x=1,map_width do
		table.insert(map,{})
		for y=1,map_height do
			local noise = love.math.noise(x,y,seed) * 4 + 1
			local terrain = terrains[math.floor(noise)]
			table.insert(map[x],Tile(terrain))
			--print(x..", "..y..", "..seed..": "..noise)
		end
	end
end
Am I doing something wrong?
User avatar
AnRu
Citizen
Posts: 69
Joined: Sun Oct 27, 2013 1:33 pm
Contact:

Re: Map generation problem

Post by AnRu »

Hi there!
This is because third parameter for noise functions is a Z coordinate, not seed :)
You need to set seed by 'love.math.setRandomSeed()' function.
So, you will recieve something like this:

Code: Select all

function gen_map()
   love.math.setRandomSeed(os.time(os.date('*t')))

   for x=1,map_width do
      table.insert(map,{})
      for y=1,map_height do
         local noise = love.math.noise(x,y) * 4 + 1
         local terrain = terrains[math.floor(noise)]
         table.insert(map[x],Tile(terrain))
         --print(x..", "..y..", "..seed..": "..noise)
      end
   end
end
'
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Map generation problem

Post by Jasoco »

Actually it doesn't appear love.math.noise is affected by any random seed. The noise generated will always look the same no matter what seed you set. (Which is my only problem with it really.) I did my own tests and indeed confirm that I can't get it to look different if I give it a different seed.

And the third parameter isn't a Z. It's just a third parameter. The love.math.noise function accepts up to 4 parameters. You can use the first three as an X, Y and Z if you want but they can be anything you want them to be if you want to get technical.

From the Wiki:
Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments.
Simplex noise is closely related to Perlin noise. It is widely used for procedural content generation.
There are many webpages which discuss Perlin and Simplex noise in detail.
Maybe one of the big guys will pop in here and give more info into how it works.
User avatar
AnRu
Citizen
Posts: 69
Joined: Sun Oct 27, 2013 1:33 pm
Contact:

Re: Map generation problem

Post by AnRu »

Jasoco wrote:Actually it doesn't appear love.math.noise is affected by any random seed. The noise generated will always look the same no matter what seed you set. (Which is my only problem with it really.) I did my own tests and indeed confirm that I can't get it to look different if I give it a different seed.

And the third parameter isn't a Z. It's just a third parameter. The love.math.noise function accepts up to 4 parameters. You can use the first three as an X, Y and Z if you want but they can be anything you want them to be if you want to get technical.

From the Wiki:
Generates a Simplex or Perlin noise value in 1-4 dimensions. The return value will always be the same, given the same arguments.
Simplex noise is closely related to Perlin noise. It is widely used for procedural content generation.
There are many webpages which discuss Perlin and Simplex noise in detail.
Maybe one of the big guys will pop in here and give more info into how it works.
Thank you with corrections, I answered only about what i saw :)
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Map generation problem

Post by Positive07 »

What do you mean by same value? I'm getting these

Code: Select all

1, 1, 9812: 3.0000813007355
1, 2, 9812: 2.9999188184738
1, 3, 9812: 3
1, 4, 9812: 4.5553710460663
1, 5, 9812: 2.7783100605011
1, 6, 9812: 3
2, 1, 9812: 2.9999188184738
2, 2, 9812: 3
2, 3, 9812: 2.9989434480667
2, 4, 9812: 2.9999188184738
2, 5, 9812: 3
2, 6, 9812: 2.7783100605011
3, 1, 9812: 3
3, 2, 9812: 4.5552086830139
3, 3, 9812: 4.5552897453308
3, 4, 9812: 3
3, 5, 9812: 4.7758421897888
3, 6, 9812: 3.0000813007355
...
This is to be expected, you can use the extra 2 dimensions that you don't need as a seed, this is good because when you need to generate the same map again you only need to store the seed value, if you want to generate a different map simply change the seed, you are using [wiki]love.math.random[/wiki] anyway so that should be what you want. What's the problem you are having with this behaviour?
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Map generation problem

Post by pgimeno »

See the big notice in [wiki]love.math.noise[/wiki].
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 4 guests