I’m using the scaled extents of a box collision as a spawning area in my game; I’m just wondering if there’s some way to enforce spacing of say, 128 units between the random points grabbed to ensure that no two objects spawn overlapping.
I’m afraid you have to keep an array of spawn points. When a new one comes along, check its distance from all the others and don’t spawn if it’s too close…
Ahh alright… I wonder, with pawns, if two spawn overlapping and you use the option for try to move but always spawn, will that take care of it?
I did this a while back. Let me dig it up and I’ll post my process. I had 4 box extents and spawn players in sequence. box 1, 2, 3, 4 etc.
here’s a vid of it during testing.
Nice. Did you do anything specifically to avoid them overlapping with each other, or did their collision and the option to move but still spawn actually take care of it?
I just took a look and all I really did was fire off a line trace to the ground from the random point. I took the hit location added 100 to Z and spawned (always spawn, adjust as needed).
Ok cool. So probably nothing really different than just spawning them in the air and letting them fall to the ground. Thanks for the help
Hey Clockwork, can you elaborate on how you would do this? I’m finding that without spacing, it’s actually causing some of the enemies to not spawn, even when I set the always spawn option.
I’ve got the extents of the box, but how do I get every point within the box?
Either that or maybe I should look into spawning a bunch of spawn point actors with settings to delete on overlap, and then spawn the enemies at the remaining spawn points. That might be an easier solution
If you want to totally fill the box, then that’s not really random. You might as well use an array of points.
The basic algorithm for not ‘over spawning’ like this:
- Choose a random point
- Check it’s not in the array ( of used points )
3a) If it is, either don’t spawn ( easy ), or loop back to 1 ( bit more fiddly )
3b) If it isn’t spawn and put the point in the array
- Back to 1
I used this method to make these islands:
Only the crucial ones are ‘real’, the rest are placed with this method.
Here’s the main loop ( I’m using a random vector rather than a box, because I don’t want stuff in the middle ):
Location used is:
The part in the loop checks the ‘vicinity’, you’ll have to do that differently for a box case. You could use a sphere trace, or just check the point’s distance from other array points.
Oh sweet, thanks so much. That actually makes a lot of sense to just add the used ones to an array and then don’t spawn if it’s already there. I was thinking the opposite; put all the points in an array and then remove them from the list once spawned.
In regards to not random if I totally fill the box, I was just thinking I’d fill it with locations to the point where there are more spawns than NPCs and then you’re still grabbing the location at random, you just end up not using all the spawns
I’ll try your solution first though