Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Have Line Renderer Create A Line Behind The Player

Discussion in 'Scripting' started by Aidy, Apr 29, 2015.

  1. Aidy

    Aidy

    Joined:
    Oct 15, 2014
    Posts:
    19
    Hi guys,

    I have a question about the line renderer component and using it in C#.

    The character in my game is going to behave similarly to the snake from the eponymous game. He'll have a tail from where the character spawns and I want the tail to follow the player, and be created in accordance to wherever the player goes.

    I'm not sure I'm explaining this well. I'll give an example of what I want. If the player moves forward 5 metres, then left 2 metres and continues moving in that direction, there'll be a line following where the player went.

    I believe I understand what I have to do but I'm unsure about the syntax of it. Would I need to create a group of Vector3s to store the origin point and one that tracks the player's position? If so, could someone point me in the right direction on how to start writing that?

    Thanks
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Aidy

    Aidy

    Joined:
    Oct 15, 2014
    Posts:
    19
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    To create a trail with colliders you'll probably have to roll your own solution. Neither of those is capable of a Tron-like tail (that is, one that stands up vertically - both are always perpendicular to the camera), either.

    If you're trying to make a Tron tail clone, specifically, the simplest solution will probably be to use either Cubes or a plain, square Sprite. You instantiate one of them for a segment between points A and B; it sets its own position to the average of those two points and rotates accordingly; and after some period of time the line segment destroys itself.

    The more complicated, but probably superior solution would be to learn to use the Mesh API to build your own trail mesh to your specifications.
     
  5. Aidy

    Aidy

    Joined:
    Oct 15, 2014
    Posts:
    19
    I see. I'll look into it, cheers c: