Normally I wouldn’t come to you guys with such an aesthetic question… but I’m really overstressed and stumped at the moment. Anyway, what I’m trying to do is make glowing bullet trails, ideally the one’s I’d like to model after are the Combine bullet trails in Half Life 2. My problem is, I have no idea where to start. Should the trail be part of the bullet Mesh? Do I use a particle system? Something altogether different? Normally I’d take the time to figure it out on my own… but I’m graduating soon and I want to get as much done on this game as possible, so any help would be greatly appreciated. Thanks in advance guys.
The TrailRenderer connects the positions of an object over several frames. This means it’s good for missiles other stuff that flies. However, for machine-gun like bullets, you really want them faster than that.
IIRC, the combine bullets don’t really move between frames - they are more like flickering randomly along the general line of fire. In order to do that, you should probably use the LineRenderer rather than the TrailRenderer.
The linerenderer needs a small script telling it where to draw.
You could also use a particle effect with Stretched Particles and Velocity Scale, (in Particle Renderer)
The effect is code-free but you wouldn’t have the same control as Nicholas’ suggestion. (Say, as you fire the effect may be partially visible on the gun barrel)
Well, I’ll probably screw around with both, since you don’t actually see the gun barrel’s here (you’re in a cockpit and the cannons are below you). Thank you both for your help.
If you really want an effect like the carbine bullets in halo you should use the line renderer. You can get point one from the gun barrel, and point two from a Raycast going forward from the gun barrel.
var linePrefab : GameObject;
var hitPrefab : GameObject;
var range = 0.00;
var damage = 0.00;
private var hit : RaycastHit;
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));
}
}
Just make a prefab of a line renderer, make sure it is set to world space (moving it around doesn’t move the line) and it has two positions (this is the default) and put that prefab in linePrefab. range should probably be a pretty big number as this is a laser and hitPrefab and damage are optional. For damage you need a damage reciever script with this in it:
var health = 100.00;
var explosionPrefab : GameObject;
function Damage (damage : float)
{
health -= damage;
}
function Update ()
{
if(health < 0)
{
Instantiate(explosionPrefab, transform.position, transform.rotation);
Destroy(gameObject);
}
}
Call Shoot() from Update() depending on some type of input. If you are lost, consult the docs.