- Home /
Bullet Tracer for Machine Gun
Hi everyone
I am scratching my head here trying to find the right question for what I need. My searches for 'bullet tracer' result in all kinds of solutions and directions to generic documentation. My problem is relatively simple (or so I think) - I need a visual hint for the bullets, or 'bullet tracer'. Please point me in the right direction so I can learning a bit more about unity. Thanks!
Answer by 3dDude · Dec 14, 2010 at 02:01 PM
Are you using the fps tutorial script?
If you are using real bullets instead of rayCasts it will be easer.
If you are using real bullets then you should add Components/Misc/lineRenderer to your bullet object...
for the material create a new material and set the shader to particles/Additive. Then create a gradient in photoShop or Gimp that looks like this(you can use this one if you like):
http://yfrog.com/45basicparticlep
here is a pic of all the settings as they should be:
http://yfrog.com/b5screenshot20101214at859p
make this object a child of the bullet object prefab...
hope this helps! and just comment if you are using the FPS tutorial script or somthing else..
This is what I meant by a billboarded texture. It works very well, and you can parent other objects to it (unlike individual particles afaik)...
I should've mentioned indeed - I am using the stock script; not sure how to make real bullets though but I will try.
Answer by The_r0nin · Dec 14, 2010 at 02:05 PM
Are your "bullet" attacks simply raycasts at the moment? If so, you have a number of different options. You could create a 2D texture and apply it to a particle emitter (if you are looking for a machine gun type effect). Simply create a prefab object and put a particle emmitter on it (with the particles coming out at high energy and on the local z-axis [something like (0,0,500) for the local velocity]. Then instantiate the prefab with the player's position and rotation (moving it slightly so that it is at the tip of your gun model) and put a script on the prefab to have it destroy itself after 1 second or so. Then do your raycast for the actual hitting (the particles would only be for show. You could make them a trigger and create damage as well... but that's a different question)
Or, if you wanted to (and have the graphics overhead available) you can do what I do and every so often while raycasting for my bullet-hits, I instantiate a prefab that has a simple 3D model of a rounded cylinder with a point-light parented to it. I then script it to destroy itself after a certain time/distance and pick an appropriate shader, and it looks pretty good. I fire this kind of tracer less often than a particle emitter (you could use the same technique with billboarded textures for less graphics hit), but I like the light effect of the point light on the tracer.
Just some ideas...
I did something along these lines: added the spark stock particles and made them stretched billboard. The effect could be working but the particles are not getting destroyed (autodestruct wont render them at all) and they are aligned to one direction only; here are the settings:
world velocity - z - 0.005 emitter velocity scale - 4
trouble is they are not rendered when I shoot upwards, and there's no collider for the hit.
added local velocity on the z axis as well but the particles never align with the camera, they are 'shot' from the same direction always.
Almost there;
local velocity z - 300 emitter velocity scale 100 stretch particles - stretched lenght scale - 100
However, the initial issue remains, if there's nothing to hit, the tracers are not rendered; not a big thing; also the particle aligns itself randomly with coliders in scene ins$$anonymous$$d of just pointing always forward from the player.
Try putting a particle collider (http://unity3d.com/support/documentation/Components/class-WorldParticleCollider.html) on the object and set the particle energy loss to a large number, and a high $$anonymous$$in $$anonymous$$ill Velocity. This way when your particles hit something, they will slow down and be destroyed almost instantly.
Your answer
Follow this Question
Related Questions
recoil and bullet tracer 2 Answers
when the bullet hits the bot it still makes the bullet hole 1 Answer
Troubles with 2D projectiles 1 Answer
Shoot 10 bullets at once 1 Answer
How do I make the bullet do damage 2 Answers