Respawn the player at the bed that is closest on foot, not through the wall
After a death the player should wake at their nearest bed, but nearest by the straight line may lie behind a cliff and take half the map to reach. Beds can also be broken or boxed in. Here is a choice that handles all of that and has a fallback.
Why this works
Players judge nearness by how long it takes to walk, not by how far a bird would fly. Measuring the walk from the spot of death finds the bed that really is closest, and avoids placing anyone behind a wall or in a sealed room.
When not to use it
Wrong when the player should choose where to wake up, as in games with several homes or a map to pick from, or for a world so large that a long search each death causes a pause. Let the player pick, or save a favourite.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 4 common mistakes and the fix
- A diagram of every state
- 42 lines of example code with 4 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Respawn the player at the bed that is closest on foot, not through the wall" (read_entry survival-respawn-at-nearest-reachable-bed) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP