How to select and move units rts style?

below is a simple example of how this could be done. i got the basics for this from Mathew Wadstein who’s youtube channel ive linked below. this is also assuming that you want the box select to be in screen space not world.

(First Picture) the important bit here is the get actors in selection rectangle which returns every actor of the filter type under a rectangle drawn on the hud. so each frame we are getting the actors under the rectangle and adding them to an array of selected actors. i added the draw rect at the end to visualize the selection box. also note the use of the gate which serves to enable and disable the selection process and serves to lock in the selected actors.

(Second Picture) to enable the selection i used a simple toggling of the gate in the hud by calling the event on left mouse click and release, dead simple. as for the movement of the characters selected thats really going to depend on your implementation so i just used a simple on right click get teh selected actors, then for each cast to character and ai move. im sure some of the casting here could be avoided and simplified but for proof of concept it works.

1 Like