The system should check to see if it
detects a floor underneath before
spawning.
The approach would depend on 1 critical bit that is not mentioned above. If there’s no floor underneath the spawn point, what do we do:
- spawn elsewhere where there is floor
- don’t spawn at all, Game Over
The general approach of sensing colliding objects is tracing:
You fire a beam down from the spawn point and check if you hit the floor.
However, this is not a great approach if you must spawn. Having 1 out of 100 floor pieces left would mean that you’d need to check up to 100 locations. Tracing is very fast so it would work anyway without a hitch but it’s a waste of resources.
A better approach is to keep track of the trapdoor’s status. Imagine having 2 arrays, one holds the closed and the other one open trapdoors only. As their status changes, they’re moved between the arrays.
When a spawn point needs to be chosen, you pick locations from a closed trapdoor array.
But again, the exact implementation would depend on the details of the game mechanics, of course.
Since you only have a handful of spawn points: add them to an array and loop + line trace; pseudo-script could look like this: