Team Spawns (WITH COLLISION DETECTION)

OK. I can get down team spawns decently. The only problem is, math.Random… It obviously doesn’t check whether or not the spot is free. I tried messing with Acecool’s code but it’s just plain not working / broken / hard to read (for me) / not what I want exactly… Now what would be a way to do collision detection for team spawns in the shortest amount of code/lines as possible? I mean if you don’t set any custom spawn functions or anything the game does spawn collision detection perfectly.

You could get all entities within your spawn area and write some sort of an algorithm to find a place where your player’s bounding box doesn’t collide with other player’s bounding boxes. Wouldn’t be short but It’d work pretty well.

If that is a little math intensive for you, you could find out if someone is in the way by checking to see if they are within a certain distance from where you’re trying to spawn the player. You could probably use the bounding box to determine that distance.

Here’s an example: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/playerselectspawn_system.lua.html

Another method, without recursion, would be to loop through all spawn positions, and add all unblocked positions to a list, then return a table.Random( ) of that list.