- Home /
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.
Answer by Matt-Downey · Oct 24, 2011 at 10:00 PM
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:

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));
}
Answer by syclamoth · Oct 24, 2011 at 07:32 AM
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.
Your answer