[Solved] Need Help with Spawning Enemies

I’ll start by saying I’ve been searching for good tutorials on spawning enemies, however, I’m not having the best of luck.

I’m trying to create a spawner for enemies that will continually keep spawning enemies in a random y position off screen. And then start to travel to the left. I’ve made a spawner sprite about the same size as the y axis of the game screen. And I’m hoping to randomly spawn from different points on the spawner without having to do anything to fancy. I’ve been following this video: How to make an endless runner in Gdevelop FREE GAME ENGINE - YouTube

I’ve done everything to spawn the objects but for some reason it’s not working. I don’t know what I’m doing wrong and any advice would be great. whether or not that’s a link to a tutorial or just simple instructions. I thank you all in advance.

1 Like

you aren’t need a sprite object as a spawner. only one line in the code.
I’m not know the tutorial wich you are want to follow, and I’m dont know what you are want to do exactly. if you just want to spawn unlimited enemies outside of the screen, you can use a timer for this, and simple coordinates.

for example:
every …-th second :arrow_right: create “enemy” obect at (withOfTheScreen) +50 ; random(heightOfTheScreen) in the correct layer.
and dont forget to set up the Z order.

I get what you’re trying to say and you’re describing exactly what I want to do. But I don’t fully understand how to execute it. What timer should I use? Where does it fall under in the conditions and actions portion? Thank you for the help.

you can learn a little bit from the timers in the wiki: Timers [GDevelop wiki].

here is my example for this:

I used the standard HD resolution this time (1360x768). and I added a “destroy when outside of the screen” behavior to the enemy object:

this soution works well for me.

1 Like

I’m still not sure what I’m doing wrong. I’ve followed this example trying to recreate what you’ve done my resolution is 288 by 512(a scaled down 4k res from what I could find). I’m in portrait mode so I don’t know if that’s why some of the code isn’t working. Also do I need to establish a variable on an object to get it to work? Perhaps that’s what I’m doing wrong.

Doing my best not to get frustrated. Gdevelop seems like a great tool but I’m honestly wondering if my time isn’t better spent with practice in Unity.

if you aren’t sure, let us tell you. attach screenshots from your events. nobody can figure out what is the problem from this: “this is not working for me”. explain in more detail what are want to do exactly, and what isn’t working.

I hope you are recalculate my numbers to fit your resolution (screen size). in any case this resolution seems incredible low to me. nonetheless, my example should work with the correct parameters.

Sorry I meant to attach a screenshot last time and just got a little punchy.

Okay so all I want to do is spawn an object off the screen on the right side and then have the object travel to the left and then disappear once it’s off screen.

I did do some recalculations but looking at the screenshot I’m posting they don’t look quite right. Here’s the screenshot:

Let me know what else you might need to help me out in this. Thank you for you patience.

I reproduce the scene with your data, and it works for me. if you want your sprites use the lower part on the screen only. if not, then just recalculate the Y coords.

what happens, or not happens, wich is no good for you? when create the object, it placed to the correct layer? may be the Z order isn’t high enough for you. is there anything, wich can obscure the created object?

Okay, it’s almost working. I figured out that one of my background objects is obscuring half of the field. I also figured out that the random in range functions means range for the y coordinate. I thought it was asking for another (x,y) so now the objects display randomly throughout the entire y-axis. I’ve looked at my layering and am slightly confused on why my asteroids are being obscured by my planet. The Planet’s Z-order is set to one and the asteroid’s is set to 10 so this shouldn’t be an issue even with the one line you gave me about the z order. Unless I have z ordering backwards.

the Z orders looks correct, the lowest Z is the most behind, and the highest is the most in front. this order is also true for the layers. may be your planet’s layer is on the top of the enemies layer.

Finally got everything figured out. The z order issue was just some bug within gdevelop itself. I didn’t change any of the layering but deleted the old instance of the planet and put it back in and then everything layered like it was supposed to.

Thanks for all your help Gyuszko. I’ll keep this thread book marked. It’s a good source of how to do a random spawn.

1 Like

I’m happy then! your welcome.