Randomly spawn object at random or set intervals

3

Stats

30,610 visits, 47,105 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 21 Sep, 2012. Last updated 19 Feb, 2019

If you're making something like a zombie survival game or just want random objects to spawn, you would find that making objects spawn randomly is a bit of a pickle.

But it's actually very simple, and can be applied to most games.

Firstly, in your layout, make a blank sprite, this is your spawner object. It can be what ever size you want. A player, and one instance of the object you are spawning (can be outside layout). Like so:

Now go to your event editor and try the following (The variable is for debug purposes, you can add it if you want):

What's happening

Every one second (this can be changed to any value, or even a random value ie. random 1-5, which will spawn at any time between 1 and 5 seconds) it will change the position of the spawner object to a random value on the map.

If the spawner object is not on screen it will spawn an object next to it and if it is on screen it will move again and try spawn something)

That's basically it!

If you are spawning zombies, you could make it that when they are created they move toward the player.

If there is anything I missed, feel free to drop a comment.

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!