offset calculation for follow camera breaks with negative values

I want to create a simple follow camera script. Currently I have this script

    public class PlayerFollowCamera : MonoBehaviour
    {
        private const float FOLLOW_SMOOTHING = 10;
      
        [SerializeField]
        private Transform player;
  
        private Vector3 offset;
  
        private void Awake()
        {
            offset = player.position - transform.position;
        }
  
        private void FixedUpdate()
        {
            Vector3 followPosition = player.position + offset;
            Vector3 smoothedPosition = Vector3.Lerp(transform.position, followPosition, Time.deltaTime * FOLLOW_SMOOTHING);
          
            transform.position = smoothedPosition;
            transform.LookAt(player);
        }
    }

In the editor the player position is at 0, 10, 0. The camera position is at 0, 10, -15. Everything works fine if the offset would result in 0, 0, -15. The problem is that the calculation breaks because the result for the z axis results in +15 because it calculates

Is my code wrong? How can I setup a smooth follow script?

Your vector subtraction is backwards. You want to do transform.position - player.position to get the offset.

thanks :slight_smile: