Camera Relative Third Person Movement

So I’m trying to make a third person character movement script which will allow me to face the camera direction and keep facing that direction until I move it in some other direction.

Here’s my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movement : MonoBehaviour {

    Transform cam;
    Animator anim;

    Vector3 directionpos;
    Vector3 storecamr;
    Vector3 storecamf;

    float h;
    float v;
    public float smooth=10.0f;


    // Use this for initialization
    void Start () {
        cam = Camera.main.transform;
        anim = GetComponent<Animator> ();
    }

    //Update is called after a fixed interval
    void FixedUpdate(){
       
        h = Input.GetAxis ("Horizontal");
        v = Input.GetAxis ("Vertical");

        storecamr = cam.right;
        storecamf = cam.forward;
        storecamf.y = 0;
        storecamr.y = 0;
        directionpos = (storecamf * v) + (storecamr * h);
        transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(directionpos), smooth);
        anim.SetFloat ("InputX", v);
    }

What happens is that the character would rotate but it would only walk in the forward direction and revert to its original rotation when the movement keys are released.

How do I modify my code to make it work?

You can load the Horizontal and Vertical motion into a Vector3, usually loading it the X and Z components, assuming Y+ is up in your world.

Then before you use it, you would rotate it by the current heading of the camera, generally taking the rotation (or a derived rotation based only on the Y euler "facing angle) and multiplying the Vector3 above by that.

Something like this:

Vector3 actualMotion = Quaternion.Euler( 0, cam.eulerAngles.y, 0) * rawInputMotion;