Random Cave Generation Within A Circle? (Based on a tutorial)

Hello! So I started following the amazing tutorials by Sebastian Lague about random cave generation and have a question as I am somewhat new to unity and not completely sure how to proceed.

Here is the video in question:

In the tutorial, the caves are created in a square shape that in controlled through public width and height variables. I was wondering if it were possible to have it instead generate within a circle? I am not entirely sure how I would go about that. One axis could be replaced with the radius or diameter, but I am not sure how it would be translated into the “greater code” per say.

I know this is a bit of a nutty question so I am sorry about that…

Thanks!

I haven’t gone through that specific tutorial, but probably there is some place in the code where it checks whether some coordinates it is about to use are inside the legal area. For a rectangular area, this might look something like:

if (x >= 0 && x < width && y >= 0 && y < height)

You can probably change that to instead check whether the coordinates are inside the radius of a circle, which might look something like:

if ((x - centerX)*(x - centerX) + (y - centerY)*(y - centerY) <= radius*radius)

You’ll need to make sure that any data structures used by the code (such as arrays or lists) are still big enough to hold all the data you are trying to use. Depending on how the algorithm works, you might find it easiest to pretend that the “walls” of your map actually fill a square area that circumscribes your desired circle, but make it so that the “empty space” where the player is allowed to go is only allowed to be created inside the circle.

It’s possible there will be other issues depending on how the algorithm works. Sometimes algorithms make assumptions or optimizations about the context in which they’re running in order to be simpler or more efficient.