Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Got some problems with Perlin Noise.

Discussion in 'Scripting' started by R0b_, Aug 31, 2018.

  1. R0b_

    R0b_

    Joined:
    Jul 11, 2018
    Posts:
    25
    I'm trying to create a biome system in my procedural generation, but the perlin noise doesn't work for me.
    Every time I try the code the Perlin noise returns the number 0.4652731.

    I've read a bit about this problem And it only seems to occur when the values given to the Perlin noise are integers, but the numbers I use in my code are most certainly fractions.

    This is the code:

    Code (csharp):
    1.  
    2. {
    3.     [Header("position")]
    4.     public Transform tf;
    5.     public Vector2 TilePieceLocation;
    6.     public float TilePieceWidth = 5 / 4;
    7.     [Header("BiomeMap")]
    8.     public StoreBiomes BiomeMap;
    9.     public Vector3 BiomeData;
    10.     [Header("Customisation")]
    11.     public int MaximumWorldLength = 3000;
    12.     public int scale = 250;
    13.     public int BiomeAmount = 1;
    14.     private void Awake()
    15.     {
    16.         BiomeMap = GameObject.Find("Tile Generation Objects").GetComponent<StoreBiomes>();
    17.     }
    18.     private void Start()
    19.     {
    20.         #region Calculate tile piece location;
    21.         TilePieceLocation = new Vector2(tf.position.x / TilePieceWidth, tf.position.z / TilePieceWidth);
    22.         #endregion
    23.         #region Calculate Biome
    24.         BiomeData.x = TilePieceLocation.x;
    25.         BiomeData.y = TilePieceLocation.y;
    26.         BiomeData.z = Mathf.PerlinNoise(TilePieceLocation.x / MaximumWorldLength * scale
    27.                                       , TilePieceLocation.y / MaximumWorldLength * scale)
    28.                                       * BiomeAmount;
    29.         BiomeMap.BiomeMap.Add(BiomeData);
    30.         #endregion
    31.     }
    32. }
    33.  
    good luck!
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Every time you run it, do the input parameters to PerlinNoise change?
     
  3. R0b_

    R0b_

    Joined:
    Jul 11, 2018
    Posts:
    25
    yes
     
  4. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    Shouldn't this
    Code (CSharp):
    1. TilePieceLocation = new Vector2(tf.position.x / TilePieceWidth, tf.position.z / TilePieceWidth);
    be
    Code (CSharp):
    1. TilePieceLocation = new Vector2(tf.position.x / TilePieceWidth, tf.position.y / TilePieceWidth);
    ?
     
  5. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Can you elaborate on that please- what makes you say that? Have you used the debugger, added debug logging, or, are you simply assuming that your code will supply changing values because that is what you think should be happening?
     
  6. R0b_

    R0b_

    Joined:
    Jul 11, 2018
    Posts:
    25
    I used
    Code (csharp):
    1.  
    2.         Debug.Log(TilePieceLocation + " | " +
    3.             (TilePieceLocation.x / MaximumWorldLength * scale) + ", " +
    4.             (TilePieceLocation.y / MaximumWorldLength * scale));
    5.  
    and it resulted in things like this:

    -5, 7 | -5000, 7000
    3, 5 | 3000, 5000
    etc...

    as it turned out I somehow mixed up the numbers in the inspector
    so the MaximumWorldLength was 1 and the scale was 1000.

    Thanks for your help
     
    Last edited: Sep 2, 2018
  7. R0b_

    R0b_

    Joined:
    Jul 11, 2018
    Posts:
    25
    well my game is 2D on a platform wich goes in the x and z direction and not the y direction, but
    a Vector2 doesn't have a z axis so I had to use the y axis. (I know long story, but no problems)