So I've been struggling to create some sort of way to create a bullet tracer effect. I discovered the line renderer and it seems to be able to create the exact effect I want: My problem is that I cannot for the life of me figure out how to make it start from my gun and fly towards my the hit.point of my raycast(s). Code (csharp): private GameObject bulletSprayPrefab; //Bullet Particle void Start(){ bulletSprayPrefab = GameObject.Find("bulletTracer"); } void ShootRay() { // Generate a random XY point inside a circle: Vector3 direction = Random.insideUnitCircle / scaleLimit; direction.z = z; // circle is at Z units direction = transform.TransformDirection(direction.normalized); foundHit = Physics.Raycast(transform.position, direction, out hit, 100); //Raycast // GameVariables.clipSize--; Instantiate(bulletSprayPrefab, spawnPoint.transform.position + direction, transform.rotation); //create particle bulletSprayPrefab.GetComponent<Rigidbody>().AddForce(transform.forward * 100000); } This makes the line render appear as I have it created in the scene view, but of course just falls to the ground. I assume that it is creating one for every raycast there is mostly because I have not devised a way to determine a rate of fire for the weapon yet so these things are created quite quickly. (facing the wrong way, but they pour out of the barrel non-the-less) ShootRay(); is called in Update with Input.GetMouseDown(0) if more of the class is needed just let me know. EDIT/ (skip to 1:10 for the effect I'm trying to create.)
Not until you suggested, no luck. This is probably so simple it's laughable... Like most of the other issues I run into. Usually I answer my problem before someone has time to answer. Thanks Renman!
Indeed, it seems to be. I tried instantiating it on hit.point of my raycasts yet... Nothing, no effect just a glowing effect where it should spawn at the barrel of my gun and I only noticed that effect because of how shiny one of my objects was. EDIT/ I'm putting it on hold for now, the frustration associated with this is too high. I'll be back bullet tracer, mark my words.
Code (csharp): private GameObject tracer; private float thrust; clone = (Transform)Instantiate(bulletTracer.transform, transform.position, transform.rotation); clone.GetComponent<Rigidbody>().AddForce(hit.point * thrust); Didn't know that I had to put the .transform on the object I was instantiating.... There is no mention of that anywhere that I can find. If I assign clone in Start() I can only instantiate the object once, I see the effect and then that is it. If I assign it on Update() you can see the object being created in the hierarchy every shot but there is no effect at all. Still frustrating but at least it's getting figured.