1
\$\begingroup\$

I am creating a top down 2D game, and I am creating randomized triangles on the ground. Such as this:image showing evenly spaced random rotation, size, and darkness triangles

This is to enhance the "knowledge" that you are moving.

But it certainly doesn't look right. Making them randomly spaced will make it more satisfying (unless you disagree).

This includes the green background (maybe creating an empty object as the parent separate from the background would be better) as the parent, and the green triangles as children. The parent has a grid layout group.

What I want to do is randomize the spacing for each individual triangle, with a minimum spacing from other triangles and a maximum spacing from other triangles.

I am not manually moving 400 triangles randomly (I could, but if I create a similar project I know exactly what to do). I would much rather hand type a 1000 line script. A script would be preferable as it could be used in other projects, but some other method is also fun. Just any method that can be re-used.

I will try making my own script that clones in a line with looping.

\$\endgroup\$
1
  • \$\begingroup\$ A grid layout and random spacing are opposites things \$\endgroup\$
    – Zibelas
    Mar 27 at 7:12

2 Answers 2

0
\$\begingroup\$

The "simplest" way is to populate a Canvas; so you don't have to worry about "rows and columns". Starting from the "origin" (0,0), you "chunk" your way from top to bottom and left to right; randomizing the position of your triangle into a given chunk (a bounding Rect).

\$\endgroup\$
1
  • 1
    \$\begingroup\$ How would you populate a canvas in chunks this way? Can you provide example C# code? \$\endgroup\$
    – DMGregory
    Mar 28 at 21:37
0
\$\begingroup\$

Create the prefab with a few possible positions of the triangle. Then each cell will contain this prefab. Then set the triangle to the random (or defined) space inside the prefab. For example each cell is 3x3 squares you put a triangle in x = 1 y = 3 position the else position is empty. You can define the position of each triangle in each cell.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .