Random Spawn -- Avoid Solid Walls

Get help using Construct 2

Post » Tue Mar 07, 2017 5:58 pm

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?
B
9
S
2
Posts: 26
Reputation: 807

Post » Tue Mar 07, 2017 8:53 pm

satellite23 wrote: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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Wed Mar 08, 2017 2:26 pm

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.
B
9
S
2
Posts: 26
Reputation: 807

Post » Wed Mar 08, 2017 2:33 pm

satellite23 wrote: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!
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, jorgmaquoi, kiki4construct and 20 guests