How do I Spawn Multiple Random Objects

  • When my player collides with a crate, the crate spawns a treasure from the Treasure Family which has 8 different treasure objects. How can I spawn more than 1 treasure object from the family when the player collides with a crate?

    I.e: Sometimes a crate will only spawn 1 treasure from the family. Sometimes 3 different treasures from the family, etc. etc. I'd like to spawn 1, 2 or 3 different objects.

    Any help would be greatly appreciated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do a system repeat action and set the repeat count to something like random(1,4)?

  • Can't get that to work. Tried changing things around but It only spawns 1 instance or i get an error message about the repeat.

  • Well, I made a little example - it's possibly a better idea to use animation frames for different treasure and instance variables if it's needed for value, etc. But the spawning of different amounts seems to work just fine.

  • you can use the following for the amount of object that will be dropped: int(random(1,4))

    This will give the number 1, 2 or 3 as a result.

    You can use this with the For loop(System/Loops/For) with the following parameters:

    Name: "drop items" (or whatever you want)

    Start index: 1

    End index: int(random(1,4))

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