title: Make canvas follow camera
body: <p>I am trying to make canvas UI object follow my camera. It works but I do not want the Y axis of the canvas object to get affected. That is, it should follow only in X and Z axis but Y should stay fixed. How do I do this?</p>
  <p>I have tried doing</p>
  <pre><code>menuCanvas.transform.position = Vector3.Lerp(new Vector3(currentPos.x, -30, currentPos.z), targetPosition, smoothFactor);
  </code></pre>
  <p>but it changes to some other axis completely.</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class SmoothCameraFollow : MonoBehaviour
  {
      public GameObject menuCanvas;
      public Camera FirstPersonCamera;
      [Range(0, 1)]
      public float smoothFactor = 0.5f;
  
      public float offsetRadius   = 0.3f;
      public float distanceToHead = 4;
  
      public void LateUpdate()
      {
          // make the UI always face towards the camera
          menuCanvas.transform.rotation = FirstPersonCamera.transform.rotation;
  
          var cameraCenter = FirstPersonCamera.transform.position + FirstPersonCamera.transform.forward * distanceToHead;
  
          var currentPos = menuCanvas.transform.position;
  
          // in which direction from the center?
          var direction = currentPos - cameraCenter;
  
          // target is in the same direction but offsetRadius
          // from the center
          var targetPosition = cameraCenter + direction.normalized * offsetRadius;
  
          // finally interpolate towards this position
          menuCanvas.transform.position = Vector3.Lerp(currentPos, targetPosition, smoothFactor);
      }
  }
  </code></pre>