Respawn character at location only if floor detected

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 :slight_smile:

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.

Use Linetrace Example

This can all depend on the game you have but a general easy way to check if there is a floor beneath something is a simple line trace.

This will return true if it detects a floor under the actor. False if no floor is detected.

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: