Toni Marino
Toni Marino

Reputation: 13

How to make limits stay the same even when changing sizes/resolutions?

This part of the script limits movement on x and y so the camera can't go outside of the game scene and it works on my 2d ortographic camera.

var pos = transform.position;
transform.position = new Vector2(
Mathf.Clamp(pos.x, xPanMax, xPanMin), 
Mathf.Clamp(pos.y, yPanMax, yPanMin));

When I change the screen size the limits are all off and I have to readjust the numbers for it not to leave the games boundaries or being able to pan around the whole scene.

Is there any way to change this code so the limits stay the same even when changing sizes/resolutions?

Upvotes: 1

Views: 566

Answers (1)

Confused
Confused

Reputation: 6278

Yes, use Cinemachine. It has dynamic understanding of the frame and scene and view.

You can learn much more about it here:https://docs.unity3d.com/Packages/[email protected]/manual/index.html

Cinemachine is a free addon package for 2018.1 and up.

Upvotes: 1

Related Questions