Try To Set Camera Bounderis 3D
Hi :) And thank You For Helping Me In Advanced ,
(I Am A Begginer)
Am Trying To Create Building Mobile Game , And I Run Across Some Problems In My Camera Settings , I Am Trying To Set The Bounderis For My Camera , But When I Am Zooming In (Changing The Orthographic Size) The Bounderis Remain The Same , So The Only Way I Can Work It Out Is When I Move My Camera I Need To Move Only The Area That Is Beeing Projected , While The Camera ITself Stay In The Same Position As IT Was , If Anyone Got A better Solution Il Be Happy To Litsen :)*
Here Is My Code (Without The Bounderis )
if (Drag)
{
DraggingTo = new Vector3(Input.GetAxis("Mouse X") * DragSpeed * Time.deltaTime, Input.GetAxis("Mouse Y") * DragSpeed * Time.deltaTime);
DraggedTo = transform.localPosition - DraggingTo;
transform.localPosition = Vector3.Lerp(transform.localPosition, DraggedTo, DragSpeed);
}
//Zoom In And Out
if (MouseWheel > 0f)
{
if (CurrentSize > MinSize)
gameObject.GetComponent<Camera>().orthographicSize = Mathf.Lerp(gameObject.GetComponent<Camera>().orthographicSize, gameObject.GetComponent<Camera>().orthographicSize - ZoomSpeed, ZoomSpeed);
if (CurrentSize < MinSize)
{
gameObject.GetComponent<Camera>().orthographicSize = MinSize;
}
}
if (MouseWheel < 0f)
{
if (CurrentSize < MaxSize)
gameObject.GetComponent<Camera>().orthographicSize = Mathf.Lerp(gameObject.GetComponent<Camera>().orthographicSize, gameObject.GetComponent<Camera>().orthographicSize + ZoomSpeed, ZoomSpeed);
if (CurrentSize > MaxSize)
{
gameObject.GetComponent<Camera>().orthographicSize = MaxSize;
}
}
}
And Another Question -
When I Am Resizing In My Bounds The View Itself Should'nt Be Out From The GameArea, Meaning That If Il Drag My Screen To One Of The Bounderis , When I Am Zoomed , If Il Zoom Out The View Would Surpass The Bounds .
~~~~~~~~~~~~~~~~~~~~~~~~~~Edit~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I Manage To Solve Half My Problem ,
//Here I Am Setting Camera Bounds (Got This Code From Answered Quetsion
topRight = GetComponent<Camera>().ScreenToWorldPoint(new Vector3(GetComponent
<Camera>().pixelWidth, GetComponent<Camera>().pixelHeight, -transform.position.z));
BottomLeft = GetComponent<Camera>().ScreenToWorldPoint(new Vector3(0, 0, -transform.position.z));
//Here I Am Applying The Bounds To The Camera
if (Drag)
{
DraggingTo = new Vector3(Input.GetAxis("Mouse X") * DragSpeed * Time.deltaTime, Input.GetAxis("Mouse Y") * DragSpeed * Time.deltaTime);
DraggedTo = transform.localPosition - DraggingTo;
DraggedTo = new Vector3(Mathf.Clamp(DraggedTo.x, BottomLeft.x, topRight.x), Mathf.Clamp(DraggedTo.y, BottomLeft.y, topRight.y), transform.localPosition.z);
transform.localPosition = DraggedTo;
//Vector3.lerp In This Case Only Made It Worst , I Dont Know If I Got Somthing Wrong But For Now Il Just Set It Direractly
//transform.localPosition = Vector3.Lerp(transform.localPosition,DraggedTo, DragSpeed);
}
I Managed To Implement Bounderis , The Problem Is That The Bounderis Resize With The Orthographic Zoom , Meaning That They Are Releative To The Camera
Your answer
Follow this Question
Related Questions
Keep 2 players on screen by moving camera back 2 Answers
Create Camera Bounds. In the camera with a different Viewport rect 0 Answers
Camera bounds with zoomable camera 1 Answer
Move camera to look around with mouse 0 Answers
Cinemachine On Mobile? 1 Answer