re spawning items inside walls problem

so i used random() to make an object respawn but the problem is … it respawn everywhere … in the air . inside blocks (walls) . behind stuff and things like that … so …
how to make it just to respawn slightly above the ground at random places ?

also tried create object Block.X()+Random(20)
Block.Y()+Random(20)
Nothing works …

Thanks always for helping …

You should pick top/walkable blocks somehow, then pick a random one and spawn the object over it:

Conditions: Variable "can_spawn" of Block is = 1 Actions: Pick a random Block Create object Enemy at Block.X() + Random(20) ; Block.Y() - 50
To use it you should create a variable “can_spawn” on every block you can create an object over. There is at least other way to select blocks that doesn’t have other blocks over it (in other words, can spawn), but it’s more complex :neutral_face:

Another way you could do it is to create an invisible “safespawn” object and place instances of it on acceptable spawn sites. Then you would create an event that uses the Pick a random object condition with “safespawn” and then create the object you want at safespawn.X(), safespawn.Y().

Obviously if it’s a huge level, placing all those safespawn objects is going to take a long time.

What I would do is respawn at the maximum possible height in case the height of the ground is different at certain points of the level and then move it down until hit the ground and once it hit the ground, set spawn to 0 to turn this spawn mechanism off and do not effect the game play further. As it would be happening 60 times a second, it would look instantly positioned right above the ground regardless how high or low the ground is, may even make it invisible until hit the ground to be sure in case there are difficulties and takes longer than a second but should not really.

In order to avoid being spawned inside block, I would add a safety check to see if the object position is the same as a block position or is it colliding with the block and change it position in a while loop until it is no longer inside the block. Again, as it is happening 60 times a second, it should look instantly spawn next to blocks and on top of the ground at any point of the level.

MattLB how to do that ?

i tried what you said and it worked but all at the same time for all the respawn points (which is not random at all) … i think i’m missing (place instances thing) …

Thanks for everyone help

That sounds like the “pick a random object” command is being done every frame (60 times a second) so that it looks like they are all being picked at once. Try adding a “Trigger once” condition to the event that is picking the random spawn site.