That is an interesting one. I don't know exactly how you are issuing movement commands, but do you need it to be so that the units start moving towards a location and you can change what formation they arrive in while they are moving or could you do in in a way where you have a triangle move option where when selected they will move to the selected location in a triangle? If so, then you could draw the triangle when the triangle move option is selected and when the move is confirmed by the user (i.e. they click on the location) it generates points within that triangle, and then iterates through your units and move them to those points. You could do this very similarly on the fly (while the units are moving) but it would involve generating the triangle and overriding their current movement command which is perfectly possible.

Generating the points on the triangle is the only somewhat troublesome part. Again, I don't know the minutia of your implementation, but you could generate a dynamically sized triangle based on the size and number of the units selected. For example, the triangle generated if you tried to triangle move 50 <10,10,10,> (can be simplified to <10, 10> since Z-axis is irrelevant for sizing) would have to be a much larger triangle than if you tried to move a smaller number of the same size units. One way of approaching this problem is by generating unit positions based on the formula for the sum of consecutive integers

1+2+3+4+…+n=(n×(n+1))/2

You could compose a triangle similar to the one seen in this picture, but instead of circles there would be units. You would only need to calculate the number of rows in the triangle by using the above formula.

Example: I select 15 units to move. I tell them to move to a location and arrive in a triangle. I know I have 15 units selected and I want the position to be a triangle I then solve for N in the above formula knowing that the sum of all rows in the triangle should be 15. This gives 30=n^2+n which gives n=5. This means we will be making a triangle like the above but with 5 rows. Each row having one unit more than the last. In your algorithm you would need to round the result up in case you get a non-integer value.Identifying the exact positions to put the units depends a lot on your implementation and the amount of space you want between the units. I realize that this explanation was complicated and long-winded but hopefully it helped you get on the right track.

answered **
Mar 06 '19 at 08:43 PM **

Crostu

31
●
1
●
3
●
2