Bullet Trail Fade (Raycast)

To whom it may concern,

I am trying to create a fading bullet trail (from a raycast) using a LineRenderer with an assigned gradient (Black--> White--> Black) texture. I can make the bullet trail look very pretty in the scene using the "Particles/Additive (Soft)" shader; however, I cannot make the bullet disappear slowly.

My question is:

How can I get a bullet to fade away?

I know that I should have something like this in a script attached to each bullet:

var visibility : float = 1;

function Update()
     visibility -= 2*Time.deltaTime;
     if(visibility < 0) this.destroy();

I just have no idea of where to plug in the visibility variable.

more ▼

asked Oct 24 '11 at 06:33 AM

Matt Downey gravatar image

Matt Downey
332 4 6 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

In order to create fading bullet tracers, make a bullet prefab with the attached script at the bottom. The BulletTrail Prefab should have a lineRenderer component with this attached material:

alt text

Use the shader called "Particles/Additive" when attaching the material to the lineRenderer.

//Script called "SelfDestruct.js" attached to the BulletTrail prefab.

var visibility : float;

var Line : LineRenderer;

function Start ()
    visibility = .5; //setting it to 1 doesn't fade until .5
    Line = transform.GetComponentInChildren(LineRenderer);
    Line.material.SetFloat ("_InvFade",3); 

function Update ()
    visibility -= Time.deltaTime;
    if(visibility < 0) Destroy(gameObject);
    Line.material.SetColor("_TintColor", Color(.5,.5,.5,visibility)); 
more ▼

answered Oct 24 '11 at 10:00 PM

Matt Downey gravatar image

Matt Downey
332 4 6 7

(comments are locked)
10|3000 characters needed characters left

Try using

lineRenderer.material.color = Color.Lerp(Color.clear, Color.white, visibility);

where visibility is a number between 0 and 1. If your material uses a tint colour, save that in Awake, and then use that instead of Color.white.

more ▼

answered Oct 24 '11 at 07:32 AM

syclamoth gravatar image

18k 8 19 93

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Oct 24 '11 at 06:33 AM

Seen: 2884 times

Last Updated: Oct 25 '11 at 06:40 PM