x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.21
Tags:
more ▼

asked Mar 06 '19 at 04:55 PM in Blueprint Scripting

avatar image

PerCat
39 1 3 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

alt text

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.

more ▼

answered Mar 06 '19 at 08:43 PM

avatar image

Crostu
31 1 3 2

avatar image PerCat Mar 07 '19 at 07:43 AM

A little. i'm mostly using bps for all of this, should have mentioned that the math and general idea isn't lost on me but. I just use the mouse to click and drag a rectangle any units within are added to an array and then I can right click to move them to the point where I right clicked.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question