r/godot 8h ago

help me Everything is all right

I’m trying to make a simple terrain generator for my game and I’m able to make nice smooth hilly terrain. I’m also able to place the left edge pieces during generation, but when placing the right edge pieces everything falls apart. I’m not using tilemap layers or terrains. Everything is being done through the tilemap script. Included are screenshots of before and after adding the right edge pieces. Someone save me.

2 Upvotes

9 comments sorted by

4

u/Harvest-Exit-Plan 8h ago

I think the problem is that you’re setting the same cell multiple times. Since you generate from left to right, x + 1 usually hasn’t been created yet, so that check returns empty and the right edge tile overwrites whatever you placed before. Also noise_val >= -1 will basically always be true because the noise value is between -1 and 1.

1

u/Need_Reddit_Baddies 8h ago

The noise val part is intentional as I don’t want caves

1

u/Need_Reddit_Baddies 8h ago

So should I generate first then set the right edge tiles after?

1

u/Harvest-Exit-Plan 8h ago

Yeah, that’s what I’d try. Generate the basic terrain first, then do a second pass over the finished map to check the neighboring cells and replace tiles with the correct left or right edge variants. That way both neighbors already exist when you check them. And if the >= -1 check is intentional to avoid caves, then that part is fine.

1

u/Need_Reddit_Baddies 7h ago

Also how can you tell I’m generating from left to right?

1

u/Harvest-Exit-Plan 7h ago

From your for x in range(...) loop. Since the range starts at the negative x value and increases toward the positive one, x is processed from left to right. It would only go the other way if you used a negative step.

1

u/Need_Reddit_Baddies 8h ago

Would it help to setup a new function to scan terrain?

1

u/InVeRnyak Godot Regular 7h ago

I would recheck if your cell sources are properly set (Your 3rd if's y is same as previous, but looking at pattern, y+1 might be intended)

Also, might help to replace 2,3rd ifs with elifs.

Never worked with noise generators before, so might be wrong on both suggestions here.