For the past week now, I’ve been working on adding a procedural debris volume to FPS Trainer.
The idea is to place down a spherical collision that envelops the level, telling it where not to spawn the debris. I can then define how far beyond the sphere debris should spawn, and in what sizes and quantity.
Just a visual effect to add some nice ambiance to the level and fill out the background.
Turned out to be a lot more difficult than I anticipated.
Getting the objects to spawn and setting the parameters was relatively easy. Getting it to not spawn any directly on top of each other has been a lot more problematic.
I’m using instances with random locations, and the node used to check for overlapping instances does not actually work, apparently.
This means that I’ve had to resort to various hack jobs to detect overlaps, and they’ve not been going well so far. As an example, one of the more valid approaches I’ve been attempting is to loop through the locations of each piece of debris already spawned, and check to see if it is too close to the current potential position before spawning a new debris.
Unfortunately this means having a loop inside of a loop, each with a maximum index matching the maximum possible number of debris spawned. So basically the code winds up running literally thousands of times, since I am working with hundreds of debris. Not a good thing.
Hopefully I can get this working soon, and I can post a guide on how I managed it.
I can see it being extremely useful for anyone working on a space game, for spawning asteroids and such. I could also repurpose it to spawn shooting targets in a sphere around the player.