Hello,
I designed a random dungeon generator. The dungeon's walls are solid.
I have a player object with 8-directional control (WASD). I want the player to spawn at a random location within the dungeon. I currently have:
[Player] On Created
set position to X: random(32, LayoutWidth-32) Y: random(32, LayoutHeight-32)
More often than not, the player spawns in an empty space, or the 8-Directional properties bump it out of a wall. However, occasionally the player spawns WITHIN the wall and can't move. How would I prevent this from happening?
I hate it when my character gets stuck in a wall lol!
There are a few ways to fix that problem. You can turn off the player collisions until they are moved or you can respawn the character if they are ovelapping the walls or any other solid objects or you can destroy any sprite that might be in the location you spawn the character.
I like the respawn method but if you have lots of solids it may take awhile before the respawn finds a suitable location.
Destroying anything the character overlaps on spawn is the simplest way. Just turn of the destroy command after they start moving or they will destroy every wall they contact.