title: How to make rts camera smooth when zooming in Unity
body: <p>right now I am trying to make rts camera zooming with panning when close to the ground. The problem I have now is that I use mouse scroll wheel for zooming and it makes the zooming feel like it's laggy. It looks like it jumps some Y value and teleports rather than smoothly move to the desired position. Also, I would like to know how to make the camera stop at the minimum Y value because what is happening now is that it stops at around 22 rather than 20 which is my minimum Y value for the camera movement.</p>
  
  <p>I tried zooming with + and - on my numpad and it worked how I wanted (smoothly zooming in and out without skipping) but not all players have numpad and I feel it is more suitable to zoom with mouse wheel.</p>
  
  <p>{</p>
  
  <pre><code>private const int levelArea = 100;
  
  private const int scrollArea = 25;
  private const int scrollSpeed = 25;
  private const int dragSpeed = 70;
  
  private const int zoomSpeed = 50;
  
  // Maximum/minimum zoom distance from the ground
  public int zoomMin = 20;
  public int zoomMax = 120;
  
  private const int panSpeed = 40;
  
  // Minimal/maximal angles for camera
  private const int panAngleMin = 30;
  private const int panAngleMax = 90;
  
  
  void Update()
  {
      // Init camera translation for this frame.
      var translation = Vector3.zero;
  
      // Zoom in or out
      var zoomDelta = Input.GetAxis("Mouse ScrollWheel") * zoomSpeed * Time.deltaTime;
      if (zoomDelta != 0)
      {
          translation -= Vector3.up * zoomSpeed * zoomDelta;
      }
  
      // Start panning camera if zooming in close to the ground or if just zooming out.
      var pan = transform.eulerAngles.x - zoomDelta * panSpeed;
      pan = Mathf.Clamp(pan, panAngleMin, panAngleMax);
      // When to start panning up the camera
      if (zoomDelta &lt; 0 || transform.position.y &lt; (zoomMax -20))
      {
          transform.eulerAngles = new Vector3(pan, 0, 0);
      }
  
      // Move camera with arrow keys
      translation += new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  
      // Move camera with mouse
      if (Input.GetMouseButton(2)) // MMB
      {
          // Hold button and drag camera around
          translation -= new Vector3(Input.GetAxis("Mouse X") * dragSpeed * Time.deltaTime, 0,
                             Input.GetAxis("Mouse Y") * dragSpeed * Time.deltaTime);
      }
      else
      {
          // Move camera if mouse pointer reaches screen borders
          if (Input.mousePosition.x &lt; scrollArea)
          {
              translation += Vector3.right * -scrollSpeed * Time.deltaTime;
          }
  
          if (Input.mousePosition.x &gt;= Screen.width - scrollArea)
          {
              translation += Vector3.right * scrollSpeed * Time.deltaTime;
          }
  
          if (Input.mousePosition.y &lt; scrollArea)
          {
              translation += Vector3.forward * -scrollSpeed * Time.deltaTime;
          }
  
          if (Input.mousePosition.y &gt; Screen.height - scrollArea)
          {
              translation += Vector3.forward * scrollSpeed * Time.deltaTime;
          }
      }
  
      // Keep camera within level and zoom area
      var desiredPosition = transform.position + translation;
      if (desiredPosition.x &lt; -levelArea || levelArea &lt; desiredPosition.x)
      {
          translation.x = 0;
      }
      if (desiredPosition.y &lt; zoomMin || zoomMax &lt; desiredPosition.y)
      {
          translation.y = 0;
      }
      if (desiredPosition.z &lt; -levelArea || levelArea &lt; desiredPosition.z)
      {
          translation.z = 0;
      }
  
      // Move camera parallel to world axis
      transform.position += translation;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I would like to have a smooth transition from the position where the camera is now and the desired position after scrolling in/out. And also I would like to know how to make the camera to stop at the minimum/maximum zoom distance rather than to stop close to it. Thank you for helping. Video how the camera movement looks like: <a href="https://youtu.be/Lt3atJEaOjA" rel="nofollow noreferrer">https://youtu.be/Lt3atJEaOjA</a></p>