To make a line following a player, just like TRON effect in Unity3D.

It has rightly been said that the day without learning something new is a day that has gone waste.

First things First, Have you ever wondered about the games that are made based on the TRON movie? We see some cool bikes with flashing trails following them. That is remarkably unique in its own way.

In terms of common language, we call them a WOW EFFECT, but coming in terms of UNity, It is a LineRenderer.

“The line renderer is used to draw free-floating lines in 3D space.

This class is a script interface for a line renderer component.”

using UnityEngine;
using System.Collections;

public class LineScript : MonoBehaviour {
     /// The line renderer component that is attached to the gameObject.. 
     LineRenderer lineRenderer;
     /// The cube that we are finding in the scene. ///

     GameObject cube; // Use this for initialization 
     void Start () { 
         lineRenderer = gameObject.GetComponent<LineRenderer>(); 
         //the cube that is in the scene has beeen assigned the tag as a player. 
         cube = GameObject.FindWithTag("Player"); 
         //It has two indexes by default. The initial point denotes the Index 0, and the 
         //final point(of the line renderer) denotes the index 1 
         lineRenderer.SetPosition(0, cube.transform.position); 

         //Set the width of the line renderer. 
         lineRenderer.SetWidth(0.5F, 0.5F); 
     } 

     void Update() { 
        //the end position of the line will follow the player where ever it goes. 
        //This is the effect that I am talking about. 
        lineRenderer.SetPosition(1, cube.transform.position); 
     } 

}

So, another script will be attached on the cube which will move in a direction..

      //Cube script. Attach this script to a cube and give it a tag name "Player" via the inspector.
         bool canMove = false;
	// Update is called once per frame
	void Update () {
		if(Input.GetMouseButtonDown(0)){
             canMove = true;
			Invoke("StopMovement",4f);
        }
		if(canMove){
			transform.Translate(Vector3.right * Time.deltaTime * 10f);
		}
	}
        //Stop the movement of the cube.
        //So, The player will stop moving and you can see a pretty good trail.
        // If you want a fancy one, then attach a pretty decent material to it.
	void StopMovement(){
		canMove = false;	
	}

So, after a lot of hard-work(Pheww) we’re finally done with Line Renderer part. Let me show you a screen shot. Of course with a fancy material.

1

2

Hope this will help you.

Sid 😉

4 thoughts on “To make a line following a player, just like TRON effect in Unity3D.

  1. thanks Sid! this has been great help
    am trying ti make the line renderer work a bit more liek the trail renderer, following the player’s path including turns and such
    do you have ideas on how to go about doing that?

    1. I’d suggest you to go with trail renderer then because it is more easy to implement and to use. Because in your case you’d have to write your own logic and maintain a list of vertices in the array and store the co-ordinate(x,y,z) values and then would have to refresh those. In any case , you can give a try to one by one both and use the one which suits your needs.

      Good Luck,
      Sid 🙂

Leave a comment