I have a 2D game with a camera that when the user clicks on an object the camera would move to that object (still dont have that working yet either) the camera would need to smoothly zoom using the orthographicsize method to the desired point. since it is 2D i noticed the camera’s z access cant be 0 or else everything disappears but i cant make the orthographicsize change in a smooth fashion. i can make it move to the desired size but never zoom it just pops into place.
Please help
If you know the desired size, you can use a Lerp function (linear interpolation) to smoothly transition the size. Here’s a script that will smoothly transition the camera zoom for you when you call ZoomCamera()
public float transitionSpeed = 0.3f;
private float desiredCameraSize;
private Camera cam;
void Start(){
cam = Camera.main;
desiredCameraSize = cam.orthographicSize;
}
void Update(){
cam.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, desiredCameraSize, transitionSpeed);
}
public void ZoomCamera(float size){
desiredCameraSize = size;
}