Crop Unity camera when zooming in / out

I have this method which pivots the camera forward / backward and left / right. I'm not sure why, but what makes the camera move well when it gets closer to terrain, but moves very slowly when zooming out?

This is how I pan the camera:

void CameraPan(){
    if(Input.GetMouseButton(2)){
        transform.rotation = transform.rotation;
        transform.Translate(Vector3.right * -Input.GetAxis("Mouse X") * 20f, Space.World);
        transform.Translate(Vector3.forward * -Input.GetAxis("Mouse Y") * 20f, Space.World);
    }
}

      

This is how I scale:

void CameraZoom(){
    float scroll = Input.GetAxis("Mouse ScrollWheel");
    if(scroll < 0){
        transform.Translate(0, 0, scroll * scrollSpeed);
    }else if(scroll > 0){
        transform.Translate(0, 0, scroll * scrollSpeed);
    }
}

      

What can I do to pan the camera at the same speed, whether it's zoomed in or not?

+3


source to share


1 answer


calculate the zoom factor - this number can be anything that represents your scale (for example, it could be the distance from the camera to the object in the center of your view)



use this scaling factor to multiply the Translate parameter when calculating the CameraPan (for example, if your scaling factor is distance, you will zoom in at a greater distance)

0


source







All Articles