Math.noise: how and why to use it?

  1. What do you want to achieve? Keep it simple and clear!
    I want learn how to use math.noise.

  2. What is the issue? Include screenshots / videos if possible!
    See above: i dont know how to use it correctly.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have look a bit on Developer Hub and Scripting Helpers, but listening to different methods and tips from different people is always better than concentrating on just one topic, tip or explanation, because everyone has their tricks and other ways to explain it.

If I’ve explained something wrong, please tell me. Thank you for taking the time to read.

4 Likes

The usage of math.noise is common during procedural terrain generation. I tested it once before. Unfortunately, I have lost the scripts used for such creation.

IIRC it generates values between the interval of -0.5 and 0.5.


Example:

25 Likes

math.noise is mostly common in games that have procedural terrain generation, i.e Minecraft. It’s very common to see in ROBLOX games that have randomized hills or terrain generation.

5 Likes

But what’s the point of it if you just use math.random?

2 Likes

math.random is for generating random numbers, and most likely will be highly inefficient due to it only being integers and not supporting decimals. Perlin noise generates something between -0.5 and 0.5.

2 Likes

To expand upon the previous points, the closer two points are in distance, the closer the generated numbers will be. This allows for much smoother generation compared to random numbers. For example, math.random might generate -0.5 and 0.5 (a difference of 1.0) for two points that are adjacent to each other, whereas math.noise might do -0.5 and -0.4 (a difference of 0.1).

4 Likes

Thx, bu when i want make a cave generator, like minecraft neather, then how to make.

You’re going a little astray from it and the generator does include the math.noise and some other programmed measures with thresholds, values etc.

I cannot provide any detail of how you can make one. Why don’t you try searching around the web and try it yourself first?

1 Like

I want to add on that math.random is a pseudo-random number generator. What this means is that the numbers will appear random, but as psuedo-random number generators work in a loop fashion, eventually it’ll loop around and you will retain the same pattern you started with, and thus the same terrain pattern. Not only is it inefficient, but it is also inaccurate in its own right. Of course, there are good applications for math.random. Without arguments, math.random evaluates from 0 to < 1. Refer to this devforum link on the math api for additional information on the documentation between math.noise and math.random.

2 Likes

It’s documented as generating values in that range, but I’m pretty sure it doesn’t actually.

3 Likes

math.noise generates numbers between -.5 and .5, not randomly, but using a procedural algorithm. it is super useful. If you generated terrain using math.random, it wouldn’t look smooth.

4 Likes

But how would you get the procedural numbers if it’s only one number?

1 Like