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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Checking when to generate a chunk

Discussion in 'Scripting' started by Noxbuds, Jul 13, 2015.

  1. Noxbuds

    Noxbuds

    Joined:
    Mar 17, 2015
    Posts:
    57
    I am making a game where everything is procedurally generated. Currently, I have chunks holding galaxies. I have a function to generate it and store it as a custom type (GalacticChunk):
    Code (CSharp):
    1. GalacticChunk GenerateGalacticChunk (Vector3 input_position)
    And a function to instantiate the galaxy:
    Code (CSharp):
    1. void InstantiateGalaxy (GalacticChunk c_galaxy) {
    The chunks are 500x500x500 units in size. How would I check when I am close enough to the edges to generate a new chunk?

    Note: the first chunk has corners of (-250,-250,-250),(250,250,250)
     
  2. 1Piotrek1

    1Piotrek1

    Joined:
    Mar 14, 2014
    Posts:
    130
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    How close is close enough?
     
  4. Noxbuds

    Noxbuds

    Joined:
    Mar 17, 2015
    Posts:
    57
    Maybe 5 units?
     
    Last edited: Jul 14, 2015
  5. Noxbuds

    Noxbuds

    Joined:
    Mar 17, 2015
    Posts:
    57
    Umm... every chunk? That's not really what I'm going for...
     
  6. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    Can't you just do a range check to the "walls" of the chunks? That's just six point-plane distance calculations.
     
  7. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    If you have a lot of empty grid spaces, try looking up octrees.