Perlin Noise not working?

float n = 0;
        float s = 1;
        float j = 1;
        float t = 0;
        for (int i = 0; i < NumNoise; i++)
        {
            n += Mathf.PerlinNoise(x * s + Seed, y * s + Seed) * j;
            s *= 2;
            j *= 0.5f;
        }
        float r = (Mathf.PerlinNoise(x * 10.3f + Seed + 166.32f, y * 10.3f + Seed + 166.32f) - 0.5f) * 100;
        return n + r;

This is code for a terrain generation. Float r is the thing that is bugged. It is not being added to the main float n. This is supposed to simulate rivers, but it isn’t doing anything.

What are x, y, NumNoise, and Seed?

What makes you think r is not added to n? What is the value of r? What is the value of n? If you’re thinking r is not being added to n, that probably means line 11 is giving a result of 0f, because you are adding them on line 12 and the computer doesn’t just skip that line. .

Have you tried printing out the values of ‘r’ and ‘n’ right between lines 11 and 12 to see if they’re what you expect?

1 Like

I forgot this forum exists. I forgot to add the code to the correct script. I was using an unused function.