I saw the new Star Wars movie and played some Jedi Knight 2 again and thought I’d try to make a lightsaber in UE4 as just a bit of fun.
- a glowing retractable blade
- animTrail emitter for more impressive visuals in motion
- attached light
- changeable colour with 1 variable
- emissive burn marks on walls that fade away
- particles of burnt stuff when hitting something
I used a placeholder character I’d done previously for something else that already had some sword animations and put a couple in just to show off motion. But I guess the only non-obvious part of how it’s done is the wall decals part, for which I don’t just put in the decals at every line trace location per frame, but I add the locations to an array and then calculate how far apart two successive points are and split the difference several times and add in additional decals if the points are far enough apart. That creates a more consistent line at lower framerates, although still not the ideal solution. Originally I wanted to use much fewer decals and stretch them between two successive line trace hit locations, but I couldn’t figure out the right vector math to rotate them correctly. (I really don’t like 3 dimensional vector math.)
Oh and the material for the decals looks a bit like this:
The top half gives it a breathing effect (although it’s hard to notice with the relatively fast fade away) and the bottom half makes it fade out over time, so there’s no instant disappearing. Also I noticed that small decals fade away really quick when you move away from them, so I used a small white circle on a big black background for the opacity so it would be “bigger” and be visible from further away.