Random Spawn -- Avoid Solid Walls

  • 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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks!

    I tried Player

    Is overlapping Wall

    random(32, LayoutWidth-32) Y: random(32, LayoutHeight-32)

    So far, I haven't had it spawn within a wall.

    This will also be helpful for spawning enemies and other objects.

  • Thanks!

    I tried Player

    Is overlapping Wall

    random(32, LayoutWidth-32) Y: random(32, LayoutHeight-32)

    So far, I haven't had it spawn within a wall.

    This will also be helpful for spawning enemies and other objects.

    Right on and looking forward to seeing your game!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)