0
\$\begingroup\$

I'm using Godot 3.5 and OpenSimplexNoise to generate my 2D topdown world with right (auto)tiles. How can I detect on which biome I'm currently standing on?

This is how I generate my map (in some way simplified pseudo code)

for (x : WORLD_SIZE_X) for (y : WORLD_SIZE_Y) m_temperature[{x, y}] = openSimplexNoise.getNoise2D(x, y); for (x : WORLD_SIZE_X) { for (y : WORLD_SIZE_Y) { float temperature = m_temperature[{x, y}]; if (temperature > 0 && temperature < 0.5) // forest m_tileset.setCell({x, y}, forestCellID); else if (temperature > 0.5 && temperature < 0.8) //desert m_tileset.setCell({x, y}, desertCellID); else //etc } } 
\$\endgroup\$
5
  • \$\begingroup\$ You should probably show an example of how you're using OpenSimplexNoise to define your biomes in the first place. There's more than one way to do that, so it's hard for a stranger to guess which approach you've taken. \$\endgroup\$ Commented Sep 20, 2022 at 21:57
  • \$\begingroup\$ It looks like you have a biome determination function right there. The inside of that for loop takes an x, y coordinate and spits out the biome type. Did you have any difficulty using this to get the biome type at the position of your player? \$\endgroup\$ Commented Sep 20, 2022 at 22:57
  • \$\begingroup\$ Well, I'm very dumb. I had the asnwer in front of my eyes but I couldn't see it. I will move my entire determination function (which is simplified here but I don't think it will be performance problem to do it every time when I move or at least when I move on another tile) to new getBiome(x, y) function which returns some enum and it should work. I guess I can't mark comment as accepted answer... \$\endgroup\$ Commented Sep 20, 2022 at 23:09
  • \$\begingroup\$ And I could always resolve all biome types at world generation loading time and save it to dictionary if it is gonna be a problem. God bless today's RAM sizes. Anyways problem solved. \$\endgroup\$ Commented Sep 20, 2022 at 23:15
  • 1
    \$\begingroup\$ You can post your own answer showing your updated code, and mark that as Accepted (after a short delay). \$\endgroup\$ Commented Sep 20, 2022 at 23:28

1 Answer 1

0
\$\begingroup\$

So the answer is my code. As the @DMGregory pointed in my question post comments I could use my determination function to find out which biome I can find. Like this:

enum BiomeType { SNOWY_WASTELANDS, //etc. } public BiomeType getBiomeType(Vector2 position) { float moisture = m_moisture[position]; float temperature = m_temperature[position]; if (moisture >= 0.0f && moisture <= 0.3f) { if (temperature <= 0.3f) return BiomeType.SNOWY_WASTELANDS; else if (temperature <= 0.6f) return BiomeType.Biome2; else return BiomeType.Biome3; } else { if (moisture <= 0.6f) return BiomeType.Blabla; else if (moisture <= 0.8f) return BiomeType.Blablabla2; else return BiomeType.Blablabla3; } } 

And I could always calculate it on loading times so I don't have to do it every time when I move like so:

public void _Ready() { m_biomeInfo = new Dictionary<Vector2, BiomeType>(); for (int x = 0; x < WORLD_WIDTH; x++) { for (int y = 0; y < WOLRD_HEIGHT; y++) { Vector2 position = new Vector2(x, y); BiomeType biomeType; //calculate biome for position here m_biomeInfo[position] = biomeType; } } } public BiomeType getBiomeType(Vector2 position) { return m_biomeInfo[position]; } 

This wouldn't work for infinite worlds, so I think the only way to calculate it on fly. It depends on the game tho for example you could connect biomes with right tiles and find out which current tile is player standing on. This would work while your ground tiles are unique to biome like "DESERT_GROUND_TILE" in my case.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.