Search Unity

Find ends of cave.

Discussion in 'World Building' started by Raika01, Oct 18, 2018.

  1. Raika01

    Raika01

    Joined:
    Dec 19, 2015
    Posts:
    3
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Hmm, my first thought would be to run a square window over the image, centered on any white (cave) point, and count how many black (rock) pixels there are. Ignore any white point whose surround is not (say) at least 70% black. Maybe even sort the points you find, in descending order of amount-of-black-surround, and then you can just spawn as many things as you need by walking the list in that order (but taking care not to spawn too close to something already spawned).
     
    Kurt-Dekker likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    I like @JoeStrout 's thinking. For such an organic cave as you have above, I would modify it a bit to pick random points in space, then raycast out a "short distance" (whatever that means in the context of the typical thickness of cavern walls) in perhaps 100 directions around each point.

    "Ends" could be considered points that hit black on their raycasts more than 70% of the time, or hit no more than one single arc of white in a given direction. You could even use the results of the raycast distances to black to "center" yourself in a little cul-de-sac.
     
    Raika01 and JoeStrout like this.
  4. Another possibility to tune the flood-fill algorithm to detect when it hit an end. Although depending on your resolution it may become slow, but in exchange, it's excellent subject for Jobs :)
     
  5. Raika01

    Raika01

    Joined:
    Dec 19, 2015
    Posts:
    3
    Thanks Kurt-Dekker , raycast to find white space, then check if this point is not to close to wall, then (in my case):
    use 32 rays around this point, if more than 5 rays don't hit wall and if those rays are spread on multiple sides, point is deleted.

    That's the result (for now):
     
    Last edited: Oct 22, 2018