- Home /
Best Way For Tracer Effect Out of 3
Hello guys, i know that this question is being repeated but i did a lot of research and still couldn't answer the questions in my head. I want to create tracer effect for my bullets. But the thing is, in my shooting script i do not instantiate bullets, i use raycasting to shoot, also with an additional "check raycast" i handle bullet drops, accuracy, penetration etc. First question, this is the right thing to do right ? Little hard but handling shooting from gun script's raycast or instantiating bullet and using raycast over there, which is better ? I believe first one and thats the way i've done it. My other questions are about tracers.
First, i tried using Line Renderer for tracer effect, but since line renderer uses a method that line renderer needs a start point and end point, and is simply a line between those points, to create tracer effect in line renderer, i believe i need to add a value to it's first and last positions, which i couldn't accomplish. Something like this :
lineRenderer.SetPosition(0,barrel.position + new Vector3(0,0,i));
lineRenderer.SetPosition(1,barrel.position + new Vector3(0,0,0.5f+i));
i += 1f * Time.deltaTime;
But as i said, I couldn't do it.
Second, how efficent is instantiating an empty game object with Trail Renderer on it, translating it to hit position and destroying it upon hit or penetrated hit. I do not look well about instantiating anything except shells and muzzles in shooting script, but i need to be sure, will instantiating tracers gameobjects with trail renderer cause an fps drop ? Considering the fact that lets say we fire a machine gun with 200 bullets and all of the bullets are tracers. ( not realistic but just to consider in max conditions )
Third, some people create empty game objects with Particle Systems on it. And on that particle system, there is just simply streched billboard particle with texture to create tracer effect. I tried this one, but particle instantiation stayed behind as we move the character. I mean it wasnt following the instantiate position simultaneously, as the character moves, couldn't figure out why. Also even i managed to create the effect without a problem, i believe setting the speeds of the particles according to hit distance can be a pain in the ass.
So I need some opinions guys, please enlighten me. What is the best way, i care about performance and usability.
Seeing as I'm a fan of the Particle System method and have used it several times without fail, how exactly does it not follow the position? Is it not parented to your gun/muzzle/weapon?
There is a gameObject called shootPosition, child of my weapon. I use this code to instantiate particle system :
GameObject instantiatedTracer = Instantiate(tracer, shootHipPositionObject.position, transform.rotation) as GameObject;
And when I stand still, it fires from that position which is okay, but when i move it looks like it doesn't follow shootPosition's position. Let me explain with images :
first image, standing still, no problems. second image, moving to right and they instantiate from the circled area of the screen ( its like they cant reach they stay behind, in the image i couldnt catch them just in time but they instantiate over there.
Also with particle another issue is that, my particle system is box shaped, with 0,0,0 as scale. Only have velocity of 15 on z-axis. So they go straight forward, i wanted them to move to hit.point because otherwise it looks ridicilous, so i wrote this :
if (hit.point != null)
{
instantiatedTracer.transform.LookAt(hit.point);
}
And another problems occur, they move to hit point when there is a hit, but if a fire into the air, they directly move to 0,0,0 position in the world.
EDIT: I now tried another way, i created a particle system in shootPosition object. And when i fire, i simply do this : prtS.Clear(); prtS.Emit(1);
it works okay, but how am i going to deter$$anonymous$$e where the particles will go ( i need them to go to hit.point because i use recoil and if they don't it doesnt match with bullet marks)
Your answer
Follow this Question
Related Questions
Shoot in a straight line 2 Answers
Uncharted4-like bullet trails: Shader, Particles or Trail Renderers? 0 Answers
Drawing a glowing line from one point to another on update 1 Answer
Raycast visible bullets 2 Answers
Trail renderer algorithm? 0 Answers