Camera follow ahead when going back

I’ve copied one of my scripts from a previous project to a new one I have for a college assignment, but I can’t seem to get my camera follow ahead to work when the player goes in the opposite direction (left). My game is 2.5D and so the player can only go left or right.

This is the script I have at the moment:

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

public class CameraController : MonoBehaviour
{
    //A SerializeField will make a private variable appear in the Inspector, but it can't be accessed by other scripts.

    [SerializeField] GameObject player;
    [SerializeField] [Range(0.5f, 3f)] float followAhead = 2f;
    [SerializeField] [Range(0.5f, 3f)] float smoothing = 1f;

    //m_min and m_max applies to the Mathf function and avoids Magic Numbers. It's purpose is to work out the lower or higher of two values and not allow it to go any lower or higher.
    //Magic Numbers involve setting a value for something that could easily be changed at a later date. If this value is used in many different places, each one has to be changed and something else could be affected by accident. Therefore it's best to set the value as a variable and reference that variable. That way, if it does need to be changed, only one instance of it will need to be changed.
    //const, or Constants, can either be numbers, values, booleans, strings etc. that cannot be changed. Don't use one for something that may change over time.

    const float m_minY = 2f;
    Vector3 targetPosition;
    Vector3 cameraOffset;

    void Start()
    {
        cameraOffset = transform.position - player.transform.position;
    }

    void Update()
    {
        targetPosition = player.transform.position + (player.transform.forward * followAhead) + cameraOffset;
        targetPosition.y = Mathf.Min(targetPosition.y, m_minY);
        transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing * Time.deltaTime);
    }
}

EDIT: Looking back on another thread about the same issue I had, it looks to be that I need my character model to rotate in order for the camera to follow ahead to the left. I’m not sure how I’d implement this. I guess I would like for my character to rotate in the opposite direction if I press the A/left arrow key and then move left. Alternatively, it’s pressed once to rotate and then pressed again to move.

This is the PlayerController script I have:

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

public class PlayerController : MonoBehaviour
{
    public Animator anim;
    public float moveSpeed;
    public float jumpForce;
    public bool jumped;
    public float gravityScale;
    public float knockBackForce;
    public float knockBackTime;
    public float invincibilityLength;

    private float jumpDelay;
    private Vector3 moveDirection;
    private float knockBackCounter;
    private float invincibilityCounter;
    private CharacterController controller;

    void Start()
    {
        Cursor.visible = false;
        controller = GetComponent<CharacterController>();
        /*jumped = false;
        if(jumpDelay <= 0)
        {
            jumpDelay = 5;
        }*/
    }

    void Update()
    {
        if (knockBackCounter <= 0)
        {
            float moveHorizontal = Input.GetAxis("Horizontal");
            moveDirection = new Vector3(moveHorizontal * moveSpeed, moveDirection.y);

            if (moveHorizontal > 0)
            {
                transform.eulerAngles = new Vector3(0, 90);
            }
            else if (moveHorizontal < 0)
            {
                transform.eulerAngles = new Vector3(0, -100);
            }

            if (controller.isGrounded)
            {
                moveDirection.y = -1f;
                if (Input.GetKey(KeyCode.KeypadPlus))
                {
                    moveDirection.y = jumpForce;
                    jumped = true;
                    //StartCoroutine(SpamBlockco());
                }
                else if(!Input.GetKey(KeyCode.KeypadPlus))
                {
                    jumped = false;
                }
            }
        }
        else
        {
            knockBackCounter -= Time.deltaTime;
        }

        moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale * Time.deltaTime);
        controller.Move(moveDirection * Time.deltaTime);

        anim.SetBool("isGrounded", controller.isGrounded);
        anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));

    }

    public void Knockback(Vector3 direction)
    {
        knockBackCounter = knockBackTime;

        moveDirection = direction * knockBackForce;
        moveDirection.y = knockBackForce;
    }

    /*public IEnumerator SpamBlockco()
    {
        if (moveDirection.y == jumpForce)
        {
            yield return new WaitForSeconds(jumpDelay);
        }
        yield return null;
        jumped = false;
    }*/
}

Anyone? :-/

Doesn’t anyone know how this could be done in Unity with a 2.5D game? I’ve still yet to find a solution. Even Cinemachine doesn’t give an option; only on positive X/moving right. :frowning: