Hey folks, quick question here.
Im using a line renderer to emulate the heat trails of machinegun fire. Somewhat like the combine machineguns in Half Life 2. Its not only for aesthetics, but is actually quite important for this game to work properly.
My biggest problem is, that I cant figure out how to set a certain lenght of the line (is that even possible?), and the next issue is to make it spawn at a somewhat random distance between the tip of my gun and whatever the gun points at. Currently im instantiating it from main cam, but thats beside the point. Is it possible to have the line spawn like this?
Heres how I currently use it (code stolen from an old post, thanks for that :))
var linePrefab : GameObject;
var hitPrefab : GameObject;
var range = 0.00;
var damage = 0.00;
//var randomstart =0.00;
//var randomstop = 0.00;
private var hit : RaycastHit;
function Update(){
if(Input.GetButtonDown("Fire1")){
Shoot();
}
//var randomstart = Random.Range( 5.0, 14.0);
//var randomstop = Random.Range(28.0, 800.0);
}
function Shoot ()
{
newLineObject = Instantiate(linePrefab);
newLine = newLineObject.GetComponent(LineRenderer);
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit, range))
{
newLine.SetPosition(0, transform.position);
newLine.SetPosition(1, hit.point);
if(hitPrefab) Instantiate(hitPrefab, hit.point, Quaternion.LookRotation(hit.normal));
hit.collider.gameObject.SendMessage("Damage", damage, SendMessageOptions.DontRequireReceiver);
}
else
{
newLine.SetPosition(0, transform.position);
newLine.SetPosition(1, transform.TransformPoint(Vector3.forward * range));
}
}
Also, I have a little script that kills the prefab after like 0.01 seconds (youre not supposed to see the bullet-trail for very long)
Any hints on this? or perhaps a better way of doing it?