Any info on camera following player movement and rotation?

I’m struggling to find a discussion or tutorial about this. Mostly it’s just people suggesting making the camera a child of the object(which will almost certainly create problems later on) or just importing the 3rd person package.

The latter is not really what I want either, as this is about programming practice.

I have a 3d object(character) with basic controls. The character simply moves forwards and backwards with W&S and A&D rotates the character. So no mouse.

So what I essentially need, is to have the camera follow and rotate ‘automatically’.

So if there is a doc or video tutorial about this, or if something can briefly throw a bit of info my way, it would be greatly appreciated.

using UnityEngine;
using System.Collections;

public class PlayerCamera : MonoBehaviour
{
    [SerializeField]
    private Transform target ;

    [SerializeField]
    private float distanceFromTarget = 5 ;

    [SerializeField]
    [Range(-89, 89)]
    private float pitchAngle = 40 ;

    [SerializeField]
    [Range(0, 10)]
    private float slerpSpeed = 1 ;

    private Quaternion targetRotation ;
    
    protected void LateUpdate()
    {
        if( target != null )
        {
            targetRotation = Quaternion.Euler( pitchAngle, target.eulerAngles.y, 0);
            transform.rotation = Quaternion.Slerp( transform.rotation, targetRotation, Time.deltaTime * slerpSpeed );
            transform.position = transform.rotation * Vector3.forward * -distanceFromTarget;
        }
    }
}