edit//
Ok so I have mapped the box from the screen to the terrain and set up bounds to test weather an object is inside it. (I know this test only works on the first quadrant, im just trying to get it working right now)
However no luck, can figure out where my logic went wrong
if(Input.GetMouseButtonUp(0))
{
Vector.DestroyLine(ref selectionLine);//just removes the box I just drew
var ray1 = Camera.main.ScreenPointToRay(originalMousePos); //first corner of the selection box
var ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);//second corner
RaycastHit hit1;
RaycastHit hit2;
Physics.Raycast(ray1, out hit1, Mathf.Infinity, ~(1 << 10)); //cast a ray from the 1st position
Physics.Raycast(ray2, out hit2, Mathf.Infinity, ~(1 << 10)); //cast a ray from the 2nd position
var objectPosition = this.gameObject.transform.position;
if((objectPosition.x > hit1.point.x && objectPosition.x < hit2.point.x) && (objectPosition.z > hit1.point.z && objectPosition.z < hit2.point.z))
{
ObjectManager.SelectedObjects.Add(this.gameObject); //test if the object is inside the bounds
}
}
End edit//
I already have a successful selection box display working. However im not sure how to detect the objects inside the selection box in order to select them.
Useful information I have is
originalMousePosition
CurrentMousePosition
those two variables are used to calculate the box.
I originally thought to check the objects coordinates against the bouding box of the selection Box. But the selection box is a 2D overlay and its in Screen (Viewpoint) coordinates. So Im not to sure where to go from here.
Exactly. I found it a lot easier to think in terms of what my camera see's than trying think of some imaginary 3D box.
– Jerdak