I’m familiar with using Unity’s Perlin noise function, inputing an x and y coordinate, which spits out a float, however I’m trying to get the same result with creating a field of points that are randomly placed, but at least some minDistance apart. I’ve tried to use a perlin noise base for this, then iterating through each point and weeding out those that are too close to others, but this iteration was very costly. I then tried just creating a perlin noise model that tends to generate pixels at amplitudes that match my needs, but there’s always some here or there that are too close together.
I need to be able to scroll through it with an offset value, hence why I’m using perlin noise as a base for this, which has a pseudo-randomness to it, instead of something from Random. But who knows, maybe Random is the way to go with this? Literally…who knows? xD
I feel there’s some approach that I’m not aware of. If anyone has any ideas, I would greatly appreciate it!
Hi @betodamian I like the direction you’re going by using perlin for this kind of thing! I’ve found that often you can manipulate the result by multiplying or dividing the x/y values (by what through trial and error), and also by multiplying/dividing the resulting value (value by trial and error), then using a very strict limiting value (like 0.99f) to weed out positions. By multiplying the x/y values by larger values, you can force the perlin result value to create placements more controlled to how you want them. I’ll add some code and an image to this answer in a little bit.
[update] Admittedly it’s been a while since I played with perlin noise and I’m having some issues getting the results I want to be able to share with you. I’m going to play with this more to see if I can tweak the script in line with more of what you’re after, so it may be a while before I post my results.
In the meantime, I have a technique I use for this kind of thing when I have random spawns I don’t want to overlap or be too close to one another. Maybe it’ll prove useful to you.
What i’ll do is, I’ll have a trigger sphere collider on the prefab set to the spacing I want (via its radius), a temporary kinematic rigidbody, and a simple script designed to detect trigger collisions of similar spawned instances of the prefab using a random priority number. What happens is, when the items spawn in, when they have a trigger collider OnTriggerEnter on a same object, the game object with the lower priority gets deleted. Once all objects are spawned, I delete all the remaining scripts, kinematic rigidbodies, and trigger sphere colliders.
You might be looking into changing the Frequency to adjust how “zoomed” the noise is:
Alternatively, you might want to look into Voronoi noise if you are looking for a more uniform spacing between the randomness:
Hi rysan, thank you for your response. Adjusting the frequency does not solve the problem of some points at a certain amplitude being too close. Here’s a screenshot of my attempt using that approach:
Voronoi Noise is something I’ve been attracted to once, but I can’t seem to find an algorithm that makes it offset-scrollable like perlin noise. Ultimately I’m going to be using these spaced points as roots to create a structure around them. This is sort of how Voronoi noise works anyways, right? A litter of points scaled out to bubbles that get cut off by other bubbles, but now we’re back to my original problem where I need a distribution of points with predictable spacing and randomness.