Hey there!
I’m currently working with RTS-style selecting box, which is easy to implement since there are a lot of topics about this feature. What the problem is that I couldn’t find a solution for selecting range of units while scrolling the map in any direction.
Here’s an attached image that shows the problem:

As you can see when I’m dragging the box to the bottom and scrolling down the map, box startPoint is not updated. What do I want to do is to move the startPoint vector respectively to the scroll speed.
I’ve tried couple of methods like Raycasting, ScreenToWorldPoint etc.
This code selects startPoint of selection box and saves the hit point with the terrain (which is not necessary, this was just another try out).
if (Input.GetMouseButtonDown(0)) {
startPoint = Input.mousePosition;
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(startPoint);
if (Physics.Raycast(ray, out hit, 1000)) {
if ("MapArea" == hit.collider.tag) {
startClickWorldPoint = hit.point;
}
}
}
…and here’s an example of the code, when the map is scrolled and the base condition here is true when selectionbox has been marked. This is an example of another try out since I cannot find any good solution.
if (...) {
startClickWorldPoint = Vector3.Lerp(
startClickWorldPoint,
startClickWorldPoint + new Vector3(
xMoveValue,
0,
zMoveValue
),
screenScrollSmoothFactor
);
startPoint = Camera.main.WorldToScreenPoint(new Vector3(
startClickWorldPoint.x,
0.1f,
startClickWorldPoint.z
));
}
Once I’ve tried to move the selectionbox (startPoint) with the size of xMoveValue (float variable, moves the camera to left/right) and zMoveValue (float, top/down).
Just to notice - lerp is not necessary here.
I’ve also attached the whole camera script.
So the question is how to make it work properly? How should I update the startPoint or maybe there is something wrong with my code.
Thanks in advance!
AmBeam.
1903566–122800–CameraOperator.cs (5.15 KB)