I need help creating a bullet tracer particle using the beam system in cascade. Currently each shot of my machine gun fires a beam from source to target, however, this looks pretty messy.
In other games (e.g. Call of Duty) tracers seem to be using scrolling textures on a beam particle system every 3rd or 4th shot for hitscan weapons. This makes them look like projectiles when they aren’t.
However because of the large variety of distances the weapon can be shot from and to, the distance of the beam varies greatly and therefore the texture stretches and looks pretty awful.
This post on the unreal forum mentions that you can feed life and beam length from cascade back to the material and use some math to modify the UV coordinates to stop the horrible texture stretching…
“I ended up going with beams anyway, since only they had the satisfactory precision. Then i feed beam life and length to the material, using those two and some math on the texture coordinates scroll the texture, creating the impression of a travelling projectile. Due to the current state of beams in cascade, i have to use the Particle Color parameters as a conduit for life/length, since dynamic parameters doesn’t seam to work.”
They don’t mention how they did it beyond that, can any suggest any ideas about how this is achieved? (I have never fed values back to a material from cascade as I didn’t even know that was possible! so I am stuck!)
One thing you can do too is to get the normal and the distance of the line trace, and spawn a mesh (not a particle system) at the hit position and scale it according to the distance, so it connects to the gun. Then you can play a timeline that animates a material parameter to scroll the texture.
If stretching it too much makes it look bad, you can establish a limit of how long your tracer can be while still looking good, and not scale the mesh (or the beam particle) past this value. Since it’s such a fast motion, you should be fine as long as the bullet trajectory reads well. You can also make an even quicker effect spawning from the gun so it’d bridge the gap if it’s too long. Does that sound like a plausible solution to you?
I can definitely see that working in a first person game, unfortunately I can’t disclose what I am working on, but all I can say is the distances weapons can fire are much greater which I think may stop this from working as well as it could due to the sheer amount of scaling on the mesh that would be involved. I did float the idea of having a max distance for the MG but it was overruled meaning that the MG needs to be able to fire the maximum distance of the play area.
I may have to resort to just firing a high speed particle off over that distance just for readability so I can keep the scale the same.
Thanks for your input though Bruno, I like the technique, I will probably end up using it for something else!
What I’ve done is use a beam to span the distance, but give it a constant world distance uv scale. Then, when firing, draw the full line from the gun to the impact immediately, but fade it out (quickly) by panning a texture across it to give it some directionality and movement with out having the issue of instant hit and psuedo projectile appearing at different times.
This was for UE3, so I don’t know how it is in UE4, but it used to be the first UV for beams was always a 0.0 to 1.0 UV range across the length of the beam, and the second UV was world space repeated. To do the panning I had a script to set a start time on that beam’s material so I could do the panning purely in the shader making it relatively cheap.