How to Randomly Spawn Collectibles on Triggers in Construct 3?

0 favourites
  • 6 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • I'm creating a game in which, when I start the layout, I need exactly 9 collectibles to appear randomly in 9 of the 28 triggers scattered around the map.

    To consider:

    • Whenever the layout is started, the collectibles should appear in different locations. Therefore, their position should be randomly drawn at each layout start.

    • I created 28 triggers in total, all of which are copies. Each trigger is a sprite with a solid color, and these sprites are scattered all over the map. The collectibles should be placed on these triggers.

    • Exactly 9 collectibles need to appear, randomly positioned on 9 of the 28 triggers.

    In short, the idea is that, when the layout starts, the game draws 9 triggers out of the 28 that exist and places a collectible item on each of these 9 drawn triggers.

  • On start of layout - repeat 9 times, system pick a random instance of 'trigger' and spawn 'collectible'.

    To stop it picking the same one twice you can use a variable on 'trigger' to mark it as used, so then the above would be pick a random instance of 'trigger' where used=false : spawn 'collectible' and set used to true.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To stop it picking the same one twice you can use a variable on 'trigger' to mark it as used, so then the above would be pick a random instance of 'trigger' where used=false : spawn 'collectible' and set used to true.

    The condition for spawning the collectibles worked perfectly, but as you lionz mentioned, there is still a chance that the collectible will spawn on the same trigger. I tried following your steps about the instance variable, but it still keeps spawning twice in the same trigger. I probably misunderstood something and ended up making a mistake. I'll send you the file if you'd like to take a look, I'd appreciate it.

    https://www.dropbox.com/scl/fi/2x2tw4uabjilutfnrgqtd/Trigger-Spawn-Test.capx?rlkey=jen63t79p14coq37k6udfi2e1&st=zw8uwskf&dl=0

  • The problem is how do Construct know which instances that had picked before if there is no list? Sure you can put boolean condition to check whether it is on true state or not. As a consequence persist behavior required as an attribute for that matter but only works if you just switch back from other layout to a layout where you laid those instances. If nothing holding the values (or state), everything will be reset after restarted.

  • You just need the condition I mentioned trigger is used=false so it only picks from ones that are not used yet.

  • You just need the condition I mentioned trigger is used=false so it only picks from ones that are not used yet.

    Oh yes, I had misunderstood. Now everything is clear. Thank you very much for your help lionz!

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