Player trail doesn't rotate properly

Hello, I’m making a TRON game but I’m encountering a problem where the trail of my player doesn’t rotate properly. I want it to rotate exactly at 90 degrees but it does this :


Here’s the scripts :
Player script :

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

public class Jscript : MonoBehaviour
{

    public TimerScript timer;
    public float speed;
    public float yAngleRotation;

    // Update is called once per frame
    void Update()
    {
        if (timer.isO == true)
        {
            transform.position += transform.forward * Time.deltaTime * speed;

            if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
            {
                // Rotation à gauche
                transform.Rotate(0f, -yAngleRotation, 0f);
            }

            if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
            {
                // Rotation à droite
                transform.Rotate(0f, yAngleRotation, 0f);
            }
        }
    }
}


Trail generator script (I copied that script from him :https://www.youtube.com/watch?v=BIKYK8qbdG0) :

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

public class TrailMeshGenerator : MonoBehaviour
{
    [SerializeField] Transform followPos;
    [SerializeField] float height = 1f;
    [SerializeField] float width = 0.001f;
    [SerializeField] float destroyTrailAfterSecond = 4f;
    [SerializeField] Material trailMaterial;
    [SerializeField] float spawnDelay = 0.01f;


    bool firstTime = true;
    GameObject trail;
    MeshFilter meshFilter;
    MeshCollider meshCollider;
    List<Vector3> verticesDef;
    List<int> triangleDef;
    bool isEven = true;
    int x;
    float currentSpawnTrailTime = 0;

    
    const string addMeshstrName = "AddMesh";

    public void SetFollowPos(Transform pos)
    {
        followPos = pos;
    }

    void Start()
    {
        if (followPos == null)
        {
            Debug.LogError("followPos is not assigned in TrailMeshGenerator.");
            return;
        }

        meshFilter = GetComponent<MeshFilter>();
        if (meshFilter == null)
        {
            Debug.LogError("MeshFilter is missing in TrailMeshGenerator.");
            return;
        }

        InvokeRepeating(addMeshstrName, 0, spawnDelay);
    }


    private void AddMesh()
    {
        MonoLine();
        if (currentSpawnTrailTime > destroyTrailAfterSecond)
        {
            RemoveMesh();
        }

    }

    void Update()
    {
        currentSpawnTrailTime += Time.deltaTime;
    }



    private void MonoLine()
    {


        Vector3[] vertices = null;
        int[] triangles = null;

        var backward = followPos.transform.position - (followPos.transform.forward);


        if (firstTime)
        {
            vertices = new Vector3[]
            {
            backward + (followPos.transform.right * -width),
            backward - (followPos.transform.right * -width),
            backward - (followPos.transform.right * -width) + followPos.transform.up * height,
            backward + (followPos.transform.right * -width) + followPos.transform.up * height,
            };

            triangles = new int[]
            {
            0, 2, 1,
            0, 3, 2,
            };

            trail = new GameObject();
            trail.tag = "Head Trails";
            trail.layer = LayerMask.NameToLayer("Trail");

            meshFilter = trail.AddComponent<MeshFilter>();
            trail.AddComponent<MeshRenderer>().material = trailMaterial;

            meshCollider = trail.AddComponent<MeshCollider>();
            meshCollider.sharedMesh = meshFilter.mesh;

            verticesDef = new List<Vector3>();
            triangleDef = new List<int>();

            foreach (var v in vertices)
                verticesDef.Add(v);
            foreach (var t in triangles)
                triangleDef.Add(t);

            meshFilter.mesh.vertices = vertices;
            meshFilter.mesh.triangles = triangles;

            isEven = false;
            firstTime = false;

            x = 4;
            return;

        }

        if (isEven)
        {
            verticesDef.Add(backward + (followPos.transform.right * -width));
            verticesDef.Add(backward - (followPos.transform.right * -width));
            verticesDef.Add(backward - (followPos.transform.right * -width) + followPos.transform.up * height);
            verticesDef.Add(backward + (followPos.transform.right * -width) + followPos.transform.up * height);

            //left face
            triangleDef.Add(x - 4); //0
            triangleDef.Add(x - 1); //3
            triangleDef.Add(x);     //4

            triangleDef.Add(x - 4); //0
            triangleDef.Add(x);     //4
            triangleDef.Add(x + 3); //7

            //top face
            triangleDef.Add(x - 4); //0
            triangleDef.Add(x + 3); //7
            triangleDef.Add(x + 2); //6

            triangleDef.Add(x - 4); //0
            triangleDef.Add(x + 2); //6
            triangleDef.Add(x - 3); //1

            //right face
            triangleDef.Add(x - 3); //5
            triangleDef.Add(x + 2); //10
            triangleDef.Add(x + 1); //9

            triangleDef.Add(x - 3); //5
            triangleDef.Add(x + 1); //9
            triangleDef.Add(x - 2); //6

            isEven = false;

        }
        else
        {
            verticesDef.Add(backward + (followPos.transform.right * -width) + followPos.transform.up * height);
            verticesDef.Add(backward - (followPos.transform.right * -width) + followPos.transform.up * height);
            verticesDef.Add(backward - (followPos.transform.right * -width));
            verticesDef.Add(backward + (followPos.transform.right * -width));

            //left face
            triangleDef.Add(x - 4); //0
            triangleDef.Add(x + 3); //7
            triangleDef.Add(x);     //4

            triangleDef.Add(x - 4); //0
            triangleDef.Add(x);     //4
            triangleDef.Add(x - 1); //3

            //top face
            triangleDef.Add(x - 2); //2
            triangleDef.Add(x - 1); //3
            triangleDef.Add(x);     //4

            triangleDef.Add(x - 2); //2
            triangleDef.Add(x);     //4
            triangleDef.Add(x + 1); //5

            //right face
            triangleDef.Add(x - 3); //5
            triangleDef.Add(x - 2); //6
            triangleDef.Add(x + 1); //9

            triangleDef.Add(x - 3); //5
            triangleDef.Add(x + 1); //9
            triangleDef.Add(x + 2); //10

            isEven = true;
        }
        x += 4;

        meshFilter.mesh.vertices = verticesDef.ToArray();
        meshFilter.mesh.triangles = triangleDef.ToArray();

        meshCollider.sharedMesh = meshFilter.mesh;

        // Debug.Log(x +" bounds->" +meshFilter.mesh.bounds.size.magnitude);

    }

    private void RemoveMesh()
    {
        verticesDef.RemoveAt(0);
        verticesDef.RemoveAt(0);
        verticesDef.RemoveAt(0);
        verticesDef.RemoveAt(0);

        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);

        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);

        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);

        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);

        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);

        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);
        triangleDef.RemoveAt(triangleDef.Count - 1);

        meshFilter.mesh.Clear();

        meshFilter.mesh.vertices = verticesDef.ToArray();
        meshFilter.mesh.triangles = triangleDef.ToArray();

        x -= 4;

    }
}

I’m a beginner so thanks for any help !

Is it possible that when your bike turns 90 degrees, it simply moves the trail emitter, because the emitter is not exactly at your rotation pivot, therefore rotation moves it around?

I don’t really know but I changed the position of the trail emitter and it’s better but it isn’t perfect :

On second thought I noticed that what you said made sense so I will take a closer look. Thanks for keeping answering me

I solved it lol, thank you very much, I reset and reconfigured the position of the bike and its childs