Search Unity

Random points relative to the the position, like Perlin Noise

Discussion in 'Scripting' started by Pasteque1, Jan 20, 2020.

  1. Pasteque1

    Pasteque1

    Joined:
    Jan 20, 2020
    Posts:
    8
    Hello guys. I would to generate some random points relative to player position until i reach the limit to give the impression of having a huge map.

    For example, Th red point is the player and the square follows him. I only want to generate the points in the radius of my orange square whatever the player position is. ( Something like that


    It generate new points in a radius but keep the already generated points. I think it use a kind of seed.

    I think it's very similar to what the perlin noise do but i already seen this kind of algorithm long time ago but just don't remember the name.

    And i would like the algorithm to do this generation in a range of 500 for example and have the circle border after.

    N.B : I can't just set the player position as a seed because if i just move from one in the Z-axis the points which are already in the orange square will disappear replaced by another.




    My code if someone want to do some else. ( Not tried but just need to edit angle and distance to only have the border )

    Code (CSharp):
    1. Random.InitState(007);
    2.      
    3.         for (int i = 0; i < nbPTS; i++)
    4.         {
    5.             GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    6.             obj.transform.localScale = new Vector3(7,7,7);
    7.  
    8.             float dist = Random.Range(0, range);
    9.  
    10.             float angle = Random.Range(0, 2 * Mathf.PI);
    11.  
    12.             Color color = Random.ColorHSV();
    13.  
    14.             Vector3 pos = new Vector3( dist * Mathf.Cos(angle), 0, dist * Mathf.Sin(angle));
    15.          
    16.             obj.transform.position = pos;
    17.             obj.GetComponent<Renderer>().material.color = color;
    18.  
    19.             obj.name = i.ToString();
    20.             print($"Angle {i} : {angle}");
    21.  
    22.  
    23.  
    24.         }
     
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    You want to "hash" the space coordinate into cells, then use the concatenate coordinate of a cell as a seed to the random function, then generate as many needed element in that cells. You should probably use a random hash because contiguous seed of typical random function aren't random.
     
    Pasteque1 likes this.
  3. Pasteque1

    Pasteque1

    Joined:
    Jan 20, 2020
    Posts:
    8
    Okey, thank's for answer ! I also remember the name waht i was looking for. Octree..