Trail Renderer Getting Wrong Rotation

I have Ball as my main player, it has trail renderer attached to give more appealing look. But when I turn ball player as left and right, attached trail render get rotated and goes inside the ground, like this image:

I want it always remain flat on ground surface and only detect ball player horizontal movements.

Here is ball player inspector details:

Actually trail’s transform never gets any rotation then also trail rotated so I become confused about this. I expect some proper explanation and solution into this.

The trail renderer is trying to face the camera, which can sometimes move parts of it through other objects. If you change the Alignment to Transform Z (or Local if you’re before 2018.2), the planes of the trail will always face away from the forward direction of the object it’s on. If you need to change the direction it’s facing, you can rotate the object.

hope that’s helpful!

As stated above, the TrailRenderer is focussing the camera.

Two things to do:

  • Rotate the object, where the trailrenderer is applied 90 degree around the x axis
  • Use “Alignment: Transform Z”

You can use this custom mesh baker by me:

using UnityEditor;
using UnityEngine;

public class MeshBaker : MonoBehaviour
{
    public TrailRenderer[] trailRenderer;
    public string exportFileName;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.B))
        {
            var combine = new CombineInstance[trailRenderer.Length];

            for (int i = 0; i < trailRenderer.Length; i++)
            {
                var mesh = new Mesh();
                trailRenderer*.BakeMesh(mesh, true);*

combine*.mesh = mesh;*
}

var combinedMesh = new Mesh();
combinedMesh.CombineMeshes(combine, true, false, false);

var savePath = “Assets/”+ exportFileName + “.asset”;
Debug.Log(“Saved Mesh to:” + savePath);
AssetDatabase.CreateAsset(combinedMesh, savePath);
}

if (Input.GetKeyDown(KeyCode.C))
{
Debug.Log(“Cleaned trail renderer”);
for (int i = 0; i < trailRenderer.Length; i++)
{
trailRenderer*.Clear();*
}
}

}
}