Hi

I use math.clamp to get a number between 0 and 1 from a math.noise

```
local height = math.clamp(h,0,1)
local temperature = math.clamp(t,0,1)
```

But unfortunately it mostly returns 0 and the chunk are mostly either snowy mountain, mountain or ocean.

The h and t are generated like this:

```
heightMap[x][z] = math.noise(SEED, x/TERRAIN_SMOOTHNESS, z/TERRAIN_SMOOTHNESS) * HEIGHT_SCALE
```

If you meant getting decimal numbers like 0.237, 0.585, or 0.177 then you could try multiplying the `t`

or `h`

by 100, then dividing it, and THEN clamping it.

Not really an expert in noises so I don’t really have any clue

1 Like

`math.noise`

mostly returns from -1 to 1. You want to get a number between 0 and 1.

-1 to 1 is a range of two, compared to the range of 1 of 0 to 1. This means you should divide math.noise by 2, getting a range of -0.5 to 0.5.

Then all you need to do is translate the range in the positive direction by 1. This ends up being `math.noise(x, y, z)*0.5+1`

.

Then you just need to clamp this result: `math.clamp(math.noise(x, y, z)*0.5+1,0,1)`

(formatted like your code: `math.clamp(h*0.5+1,0,1)`

). (Note this still tends towards 0 and 1, but it shouldn’t be very noticeable.)

For more info, check out the DevHub:

1 Like