RTS unit selection that don't move with camera?

I just made a RTS unit selection following this tutorial: RTS Marquee Selection (Select Units by Dragging a Rectangle) in Unreal Engine 5 - YouTube He uses ,Draw Rect" node to draw the selection rectangle and ,Get Mouse Position" for getting locations of mouse. But when you draw the rectangle and moves your camera the whole rectangle moves with you. In almost every RTS I played when you select and move your camera to the side one point stays in the same place and second moves with you so you can select a large number of units. I am wondering how could I do something like that ?

So because the Draw Rect function takes in X and Y in screen space, when you move the camera it will of course move that top left with you as well.

There are a few ways of handling this, but at the basic level: You’ll want to detect when you move the screen, and to change the “draw rect” to be subtracted by how far you move the screen.

So for example if you go to the edge of the screen and pan right, you want to subtract the amount you move from the X or Y values on the draw rect.

You’re basically doing the opposite to the rectangle as you move the camera.

You can do this the other way too. If you move left you add, if you move right you subtract. This should keep the box stationary.

When you move right, you should adjust X and Y, because the left rectangle start is based on the X and Y inputs. But when you move left, the right side of the rectangle is denoted by the width and height. So you should modify those.

That seems like and intelligent way to do it :smiley: thanks I will try.

1 Like