How do I spawn random objects from a set of objects

0 favourites
  • 6 posts
From the Asset Store
*********** Fidget popper tile sets **************
  • I am making a falling game and I wanted to make it so as obstacles spawned, they could be one of 6-7 random obstacles. Is the only way to do this from a massive is statement, or can I do it programatically? The if statements are getting out of control since there are 15 permutations of the configuration, then wanting to add 4-6 options for each of 4 spots, its getting a little insane if I can do it programatically.

  • You could check out the simple flappy birds tutorial that is on the site. Yes I know its a sideways game but its still the same concept.

    Move out of the way of randomly generated obstacles.

  • Rather than a bunch of if statements spawning separate objects, incorporate all of your obstacles into a single object as different animations or frames with a corresponding number.

    Example:

    On spawn trigger:

    set localvariable to floor(random(x,y))

    spawn obstacle

    set obstacle animation to localvariable

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • HJ1, I did it with both. Setting the animation worked, but the frame did not. If you set the frame and stop the animation, it will change every time a new object spawns, but setting the animation worked like a charm.

  • Just a thought, but is it possible that when using frames you haven't set the animation speed to 0?

    Happy that the animation method worked for you either way!

  • If you get all your obstacles into a family, then you can just spawn the family. It wil choose a random object from the family. It's a bit less of a hassle than choosing a random animation, and each object can have it particular behaviour.

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