Trying to get a 2D trail vfx using math and the line renderer

Hi,
I’m trying to get an effect similar to this using the line render and some math

I want to layout the vfx on line renderer before I try to do it on a mesh. I think I’m getting close but I have a few things to iron out, here my progress so far.

I don’t know how to dim out progressively the left end part. I’m open to suggestions. Here’s the code:

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

[RequireComponent(typeof(LineRenderer))]
public class SimpleLineRenderer : MonoBehaviour
{
  
 
    public int lengthOfLineRenderer = 20;
   
  
   
    public Vector3 based = Vector3.zero;
 
    public float amplitude;
    public float decay = 5;
  
  
    public float wavelength;
    public float waveSpeed;
    public float y;
    public float x;
    public float smallValueOnX = .001f;
   
    void Start()
    {
     
        GetComponent<LineRenderer>().positionCount = lengthOfLineRenderer;
    }

    void Update()
    {
        LineRenderer lineRenderer = GetComponent<LineRenderer>();
        int i = 0;
        float k = 2 * Mathf.PI / wavelength;
        float w = k * waveSpeed;

        while (i < lengthOfLineRenderer)
        {
            x = i * smallValueOnX;
          
            float s = Mathf.Pow(Mathf.Sin(Time.time/i), decay);

            float z = Mathf.Pow(Mathf.Abs((Mathf.Sin((Time.time) / i))), decay);

            y = Mathf.Abs((Mathf.Sin((k * x + w * (Time.time))))) * (amplitude);

            //Debug.Log("Z: " + Mathf.Abs( z));
            Vector3 pos = new Vector3(x, z  * ( y), 0);

            //Vector3 pos = new Vector3(x, Mathf.Abs(Mathf.Sin(k * (x + w) * (x + w) ) * (w - x) * Time.time) * amplitude);
           
            lineRenderer.SetPosition(i, pos + based);
            i++;
        }
    }
}

Another way to achieve that vfx would be to use particle effects system and spawn half circle, but my goal is to learn it using math. If anyone got an idea on how to smooth out the left end part like in the example feel free to give me ideas and suggestions.

Using math:

  • devise a function that has the falloff you need

  • apply it to the displacement near the end of the trail as you like.

Using smart math:

  • make a public AnimationCurve

  • curve it how you want it to falloff

  • call curve.Evaluate() to make that falloff of the trail.

looks good ^