Hi,
I’m trying to make a respawn system that will chose between a couple spawn points but will only spawn at one if it detects a floor underneath.
For example on the level I’m working on all the floors have been replaced by randomly falling trap doors. So I don’t want the player to respawn over a open trap door and die again. The system should check to see if it detects a floor underneath before spawning.
Any ideas on how I can achieve this? Any help is appreciated
Do a downward line trace at the proposed spawn point. If you find a trap door, don’t spawn, but if you find a floor ( what is that? mesh? ), then it’s ok.
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: