Unity Sword Trail Effect

How to create a sword trail effect in Unity using mesh generation and shader texture offset

I added basic attack animations to my character controller.

Basic attack

Swinging the sword felt empty. Games I’ve played always had that afterimage trail effect when swinging fast.

Implementation

Generate a mesh along the sword’s trajectory.

Sword trajectory as mesh

Draw a texture on the mesh and push it with a shader. The timing needs to follow right behind the sword’s path.

To sync the timing, adjust the shader texture Offset while watching the sword in the animation.

After searching for how animation stores shader texture values, I found Material._MainTex_ST.

Now I can control shader values through animation.

Sword trail texture following the blade

Tip: Set the shader texture mode to Clamp instead of Wrap. Otherwise the texture keeps repeating. With Clamp, it extends the last pixel seamlessly.

Final result

Basic sword trail effect done. Next step: make it 3D and add more options for fancier effects.

Extra Tip

Broken option

When keying the animation, use the Broken tangent option to prevent the texture from visibly snapping back to the start when the attack animation ends.

Hugo로 만듦
JimmyStack 테마 사용 중