- Home /
 
the code of camera rig in tanks Game can explain how this works?
  private void Zoom()
     {
         float requiredSize = FindRequiredSize();
         m_Camera.orthographicSize = Mathf.SmoothDamp(m_Camera.orthographicSize, requiredSize, ref m_ZoomSpeed, m_DampTime);
     }
 private float FindRequiredSize()
 {
     Vector3 desiredLocalPos = transform.InverseTransformPoint(m_DesiredPosition); 
     float size = 0f;
     for (int i = 0; i < m_Targets.Length; i++)
     {
         if (!m_Targets[i].gameObject.activeSelf)
             continue;
         Vector3 targetLocalPos = transform.InverseTransformPoint(m_Targets[i].position); 
            Vector3 desiredPosToTarget = targetLocalPos - desiredLocalPos;
         size = Mathf.Max (size, Mathf.Abs (desiredPosToTarget.y)); 
         size = Mathf.Max (size, Mathf.Abs (desiredPosToTarget.x) / m_Camera.aspect);
     }
     
     size += m_ScreenEdgeBuffer;
     size = Mathf.Max(size, m_MinSize);
     return size;
 }
 
              The orthographic size of a camera is half its height in world units. this code is calculating the necessary orthopraphic size to fit all m_Targets into the view frustum. For this, it transforms those positions into its local space (InverseTransformPoint). I don't see what desiredLocalPos is, so cannot say why it's subtracted. Nevertheless, it get's the absolut maximum out of the y position and the x position in respect to the camera aspect (calculating this out so it's calculated as if the camera viewport were reactangular). Then adding a margin kindof (m_ScreenEdgeBuffer) and picking between the m_$$anonymous$$inSize and the final size result (could be smaller than m_$$anonymous$$inSize). Finially the camera othographic size is smoothly damped towards that value.
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Cinemachine freelook cam Crossplatform Input Movement 0 Answers
Dissable lights per camera? 2 Answers