# Roblox Math.noise No ratings yet.

Posted on

Roblox Math Noise is the term to call something that is able to fix three important issues of Roblox. This one that makes it good for procedurally generated stuff. This thing also could occur to have some precision issues when you use relatively big numbers.

What are those three important issues? The first one is known as aperiodic. The result of the first one is not predictable. The second one is called smooth. The result of it is never sharp and neither are its derivatives. You can call the third one the multidemensional. The result of this one is able to work well in more than one dimension up to three. For those who want to know, here is the code of the visualization:

1 for i = 1, 15 do

2 print( string.rep(“#”, math.random(10, 20) ) )

3 end

01 ###################

02 ####################

03 ###########

04 ##############

05 ###########

06 ####################

07 ##############

08 ############

09 ##################

10 ############

11 ##################

12 ##################

13 ####################

14 ###################

15 ##############

There is another selection that you might want to be used to something like math.sin:

1 for i = 1, 15 do

2 print( string.rep(“#”, 10 + 5 * math.sin(i) ) )

3 end

01 ##############

02 ###############

03 ###########

04 ######

05 #####

06 #########

07 #############

08 ###############

09 ############

10 #######

11 #####

12 #######

13 ############

14 ###############

15 #############

The term smooth means that it is obviously repeating itself. In addition, it is able to look worse and worse the more you see it. In this case, you are able to sort of solve this issue by adding two difefrent sin waves together:

01 #############

02 ##############

03 ############

04 ##########

05 ##########

06 ############

07 ##############

08 ##############

09 ############

10 #########

11 #######

12 #######

13 #########

14 ##########

15 #########

Then, how to get out of this issue? In general, all you need to do is to replace math.sin with math noise and you will be able to get what you want. Before replacing math.sin, you have to know that there are several important considerations. The first one is that math.noise is bounded between -0.5 and 0.5**. The second is if x and y differ by more than 1, then the math.noise (x) and the math.noise (y) are completely different and has nothing to do. It means that if you sample from math.noise, you need to sample closer than 1 together.

1 for i = 1, 45 do

2 print( string.rep(“#”, 10 + 10 * math.noise(i / 5) ) )

3 end

01 ###########

02 ###########

03 #########

04 #########

05 ##########

06 ############

07 ###############

08 ###############

09 ############

10 ##########

11 #########

12 #########

13 ###########

14 ###########

15 ##########

There some good things that you can get when you use math.noise (x,y,z). For example, if you generate the terrain, you can get the interesting, random, and smooth height at position (x, math.noise (x/10, z/10, z). For example:

01 for x = 1, 100 do

02 for z = 1, 100 do

03 local height = (math.noise(x / 20, z / 20) + 2) * 50

04 local p = Instance.new(“Part”, workspace)

05 p.Locked, p.Anchored = true, true

06 p.Size = Vector3.new(4, height, 4)

07 p.CFrame = CFrame.new(4 * x, height / 2, 4 * z)

08 wait()

09 end

10 end