how do I make a random distribution in the grid?

0 favourites
  • 11 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • first of all I'm sorry for my bad english :D

    i want to randomly show different players in a grid.

    i managed to get the players to randomly spawn in the grid.

    but sometimes these appear in the same grid, how can I prevent that

    thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There are several different ways of doing this. For your purposes, the simplest way might just be to do an extra check after spawning to see if any player objects are overlapping, and if they are, to reassign them to a new square. You'll want to do this in a While loop to ensure you don't randomly put them into a different occupied cell. (This isn't a great idea if you have a very large number of player sprites, but for just 3, this should work just fine).

    Eg. On start of layout:

    -------Spawn Player 1 at random coordinates

    -------Spawn Player 2 at random coords

    -------Spawn Player 3 at random coords

    --------------WHILE Player 1 is overlapping Player 2 OR Player 3

    ---------------------Set Player 1 position to random coords

    --------------WHILE Player 2 is overlapping Player 1 OR Player 3

    ---------------------Set Player 2 position to random coords

  • Thank you!

    did i do something wrong? It doesn't work for me

    the white and blue still overlap the red

    code

    game

    i tried it differently, then the "players" are no longer in the grid

  • Yeah, I'm afraid you haven't quite got that right.

    You've got this:

    Player 3 > Is overlapping Player 2

    Player 3 > Is overlapping Player 1

    Right now, this event only executes if BOTH conditions are true. We don't want that (it's extremely unlikely that all 3 objects will overlap, so this will basically never run) - we want it to run if EITHER condition is true.

    To do that, you need to add "OR". To do this, right-click on the condition block and click "Make 'OR' block".

    That will give you

    Player 3 > Is overlapping Player 2

    OR Player 3 > Is overlapping Player 1

    :)

  • You are better off designing it so that the different player objects are never spawned in the same location. This will avoid having to then move them afterwards.

    Have a look at this example:

    1drv.ms/u/s!AkmrWgxeuxlKhIhJtJkjanOQUXHDVA

  • Hey, hope everyone is doing well!

    I read through everything and was trying to have bigger/custom Objects. The only things I've changed is the amount of times each chooser fires off. And I made "Player 1" Bigger and adjusted the origin accordingly.

    My problem is as you can see with the image included the only effected object that cannot be overlapped in the upper left corner. (Initial Chosen Object).

    I downloaded your example and went through it extensively multiple times. I'm very new to construct and completing my 4th course/tutorial series so I am really new to this engine. The dropbox link is the modified file.

    dropbox.com/s/czfc24mk46e6xnw/gridchooser_differentsizes.c3p

    Was wondering what I am doing wrong here. Tried deleting overlapped "grid" Objects and haven't even managed to manually turn individual one's Variable to active. I could care less what happens to older objects overlapped even though deleting them makes more sense since they are useless after the fact.

    Thank you for your time, it's much appreciated!

  • I'm not sure what it is you are trying to do?

  • I'd like the bigger Blue Box to never be overlapped. Since it get's created first. I figured the best way would be to destroy any of the other Options from the grid. From what I can understand code is run from top to bottom. I am just having trouble actually getting it to function at all. Or even check before it ticks active variable, check if overlapping another "PLayer" Object. I made the Blue Player 1 object bigger and adjusted the anchor point accordingly is all I've done.

    In the image I posted is the only thing that doesn't overlap. Initial spawn point. AKA top left of the bigger box.

  • The created object is the yellow check mark. After it is created it then creates 3 white and 1 red box. I kept restarting the project until I got lucky and got a picture showing the worse case scenario of my problem. Other objects can spawn on the opposite corners of the Blue Player 1 OBJ.

    Sorry, hope this helps. And thank you for your help!

  • I'm sorry, this project was created to specifically show a randomised distribution on a fixed grid. If you want to make one of the distributed objects larger and not have it overlap, then adjust the grid size in the editor.

    If you destroy the other grid objects the whole project won't function.

    I think you might want to create a new project from scratch to do what it is you are trying to do.

    I still don't understand it, but perhaps someone else might.

  • Makes sense. Thanks

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