Jump to content
  • Advertisement
Sign in to follow this  
vicer1234

Perlin Noise + tile mapping

This topic is 2349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
I am trying to build a 2d platformer, in that I want to have procedural maps generation using Perlin noise.
The idea is to have a Terraria type of game environment.

For that purpose I have created a Perlin noise function and it generates random values when passed two values (X,Y)

But I am confused about the next step to be taken for the implementation:

My doubts are:


1) Whats the logic for the tiles (procedurally the map ) to get displayed as the CHARACTER moves left,right, down, and up.
Is it like taking the co-ordinates of the character as a REFERENCE which is moving at any point of time for example like the character is at (200,100) and the map width is 1024 X 768
then
using that point (200) as a reference and generate map 1024 width wise && using (100) as reference generate map 768 height wise.

2) If my map is 1024 x 768 ie equal to the game window at any point of time then do I need to pass each pixel value and generate the noise values and store it ie

for(int i = 0; i < 1024; i++)
{
for(int j = 0; j < 768; j++)
{
NoiseGenerated [ ] = PerlinNoise( i, j);
}


or
is it like taking that area only where the tiles will get displayed. I mean if the tiles are displayed in area like
width: X' min starting from = 0 and X max ends at = 1024
height 'Y' min starting from = 0 and Y max ends at = 384 ie 768/2

Then the noise is generated for (1024 = X, 384=Y)

Is this the way of doing it????

3) How to relate the value generated from Perlin noise to tiles ie I have tiles of GRASS, WATER, STONE ETC


I hope the questions which i have asked make sense !!!

All suggestions are welcome

Share this post


Link to post
Share on other sites
Advertisement
I am still working on it....But I hope the question I put forward is understandable and it also make sense!!!

Note:(Just a polite update)

Share this post


Link to post
Share on other sites
3) How to relate the value generated from Perlin noise to tiles ie I have tiles of GRASS, WATER, STONE ETC
With perlin noise you will get a value in a specific range (0..1 or 0..255 or whatever)
Just write a function that maps values from that range into tiles (I assume each tile in your game have a different ID, like rock = 1, grass=2 etc)
This is the simplest way, then you just improve on that, and you can make this mapping as complex as you want (taking adjacent tiles into account, etc)

Share this post


Link to post
Share on other sites

3) How to relate the value generated from Perlin noise to tiles ie I have tiles of GRASS, WATER, STONE ETC
With perlin noise you will get a value in a specific range (0..1 or 0..255 or whatever)
Just write a function that maps values from that range into tiles (I assume each tile in your game have a different ID, like rock = 1, grass=2 etc)
This is the simplest way, then you just improve on that, and you can make this mapping as complex as you want (taking adjacent tiles into account, etc)


Thanks for the reply.
I am working on same logic as you have mentioned for the 3) part

I just wanted to know the parameter (X,Y) which is passed to PerlinNoise() function
how they are determined ie X and Y is it characters world position?

Share this post


Link to post
Share on other sites
X and Y are the world positions yes, don't forget to multiply them with a scaling factor too.

As for determining what is grass, etc, etc. There are various ways for various purposes. First off, you will want to add several passes of perlin noise functions together with different scaling factors and amplitudes, what is often referred to as "octaves"... this is what gives the terrain large features as well as small features. In 2D you might not need or want all that many octaves though.

So when it comes to determine what kind of type of tile it should be, you simply apply a threshold to the value from the perlin noise function, like >=0.5 or <=0.1, etc... you may also want to add the height with some scaling factor to that value, to allow there to be air above a certain level. However, it's rarely useful to determine different tile types from the same noise function. It will create obvious and uninteresting patterns, you will want to sample from different perlin noise functions and determine based on a combination of all of them.

But there's a lot of trial and error too... different regions could be determined mathematically/programatically or by using perlin noise. Same for ore, etc. But those are the basics.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!