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

May 15, 2013 | Rishabh Agrawal | General

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 a 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.

Click on the images given below to have a clear view, on what is going in here

Hope this will help you.

 

 

Post By:- Siddharth Verma

 


THE AUTHORRishabh Agrawal

Rishabh Agrawal is the founder of Creatiosoft, a company focused on creating high-quality software for the iGaming industry, specialising in poker and card games. With years of experience, Rishabh is dedicated to delivering engaging and user-friendly gaming experiences. Through this blog, he shares his passion and insights to help readers understand the latest trends and advancements in iGaming.

Comments are closed.

Recent Posts

The Future of Mobile Gaming: What to Expect in the Next 5 Years

Over the years, mobile gaming has seen amazing development and innovation utilized by the game development company in India. It…
06 Jun 2023 Rishabh Agrawal

How Do I Get Started With NFT Gaming?

The popularity of the NFT game has created a different fan base. There was a time when games were a…
18 Jul 2022 Rishabh Agrawal

What Are The Top Trends in NFT Marketplace 2022?

The NFTs are the new engaging and revolutionary technology across the globe. Though, these non-fungible tokens appeared for the first…
09 Jun 2022 Rishabh Agrawal