I’m just trying to add boundaries to this script here (it drags my camera around the screen). I want my camera to stop if it reaches a certain distance away. I’ve tried using a distance check, but once I get outside that, I can’t move the camera at all anymore… Here’s my code:
if(blah)
{
float HitDist;
Ray MouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 GroundNormal = new Vector3(0.0f, 1.0f, 0.0f),
GroundPoint = new Vector3(0.0f, 0.0f, 0.0f);
Plane GroundPlane = new Plane(GroundNormal, GroundPoint);
if (m_Drag)
{
GroundPlane.Raycast(MouseRay, out HitDist);
Vector3 CurClickPos = MouseRay.GetPoint(HitDist);
test = Vector3.Distance(new Vector3(0,0,0), transform.position);
Camera.main.transform.position += m_MouseDownPos - CurClickPos;
}
else //if (Input.GetMouseButtonDown(0))
{
GroundPlane.Raycast(MouseRay, out HitDist);
m_MouseDownPos = MouseRay.GetPoint(HitDist);
m_Drag = true;
}
}
}
else
m_Drag = false;
thoughts on how I could do this? I realize it is using PC controls right now, I just haven’t changed them to touch controls yet, but posted my question here so people would assume I wanted a portable optimized solution.