Search Unity

custom linerenderer [solved]

Discussion in 'Scripting' started by BloodMarked, Dec 3, 2017.

  1. BloodMarked

    BloodMarked

    Joined:
    Dec 11, 2013
    Posts:
    28
    i want to create a dynamic trail behind an object (sword).

    basically the unity linerenderer and trailrenderer dont quite do the job.

    so can i acess and modify the linerenderer script somewhere?
    or what is the best practice to create and modify vertex data in realtime in unity?

    any tip or link to documentation appreciated


    what i am trying to do:
    the trail is supposed to behave similar to a flag, meaning the quads span between the two ends of the blade.
    adding a new quad which connects to the new positions every frame, removing (or recycling) one, scrolling uvs etc
     
  2. BloodMarked

    BloodMarked

    Joined:
    Dec 11, 2013
    Posts:
    28
  3. BloodMarked

    BloodMarked

    Joined:
    Dec 11, 2013
    Posts:
    28
    i found and made what i was looking for
    a quick rough implementation for other to use

    needs to be attached to a GameObject with a Mesh filter and mesh renderer, p.e. the basic plane

    overwrites the mesh content on runtime
     

    Attached Files:

    Quatum1000 and Munchy2007 like this.
  4. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Thanks for the script!! I wrote a complete multi line renderer from your script that combines, weld, optimize all vertices.

    There are 2 small issues I have fixed.
    1) The length of the horizontal UV's are too short.
    2) the texture is mirrored
    Code (CSharp):
    1. uvs[i] = new Vector2(0f, (float)i / (float)vertices.Length);
    2. uvs[i + 1] = new Vector2(1f, (float)i / (float)vertices.Length);
    exchange with:

    Code (CSharp):
    1. uvs[i + 0] = new Vector2(1f, (float)i / (float)vertices.Length-2);
    2. uvs[i + 1] = new Vector2(0f, (float)i / (float)vertices.Length-2);
    Further your need:
    Code (CSharp):
    1. m_mesh.RecalculateBounds();
    2. m_mesh.RecalculateNormals();
     
    Last edited: May 3, 2018