Placing GameObjects on a triangle

I have a number of GameObjects that I want to place in the scene, I want their centers placed in the upper sides of a triangle and I want them equispaced.

The first GO always start at the bottom left, the others GOs will follow.

I’m reporting an example of the desired result in case of even and odd numbers.

I’ve spent quite a few hours thinking a good method to do it but with no results.

The closest thing I’ve come across is to use the mathematical formula of a triangle wave, which is something like : abs(mod(x,2)-1) but I did not quite understand the role of the parameters moreover it’s seems a bit too complex.

If you have some ideas, please share!
Thanks

7489397--921887--triangles.jpg

I would do it in this order:

Iterate an integer from 0 to N-1 (where N is your triangle count) and:


- generate the X and Y parametrically from that fraction:

--> x = width * fraction

--> y = height * fraction * 2 // 2x-steep slope
--> if fraction > 0.5f:
----> y = height * 2 - y // inverts the slope for the second half```
1 Like