Best way to have groups of units move in formation? (rts-style)
I have made it so I can left click and draw a rectangle on release it captures actors of class and adds them to an array, any units within the rectangle are selected. I can then right click and move the units to where I want.
For now it is a simple point under where my cursor happens to be when I right click. What I'm wondering is what is the best way to have units move to an area in a set formation? Like say select and move; they form a square or a line. Or an arrow etc... Doesn't matter.
Could I forloop and have it designate points in a shape around where I right click? Draw another rectangle of "x" size and move them within ti's bounds on right click?
I realize this is advanced stuff as far as my skill goes as well as rts stuff in general and there's no real tuts out there for moving or creating unit formations.
Any help appreciated! Thanc.
asked Mar 06 '19 at 04:55 PM in Blueprint Scripting
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
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
Follow this question
Once you sign in you will be able to subscribe for any updates here