It’s still possible to have swords play a role in a modern or futuristic settings. You just need to shape audience expectations, and you can do this a few different ways, each with its benefits and potential pitfalls.
1. Nerf Guns
For a straightforward approach, reduce the destructive power of guns in your setting. If firearms are less reliable or there are good countermeasures against them, it becomes more feasible to fight hand to hand. We see this in Pacific Rim, where the Kaiju are armored well enough against the Jaeger’s weaponry that it mostly comes down to brawls. Because the scale is already outside our norm and the movie primes us to see melee as more effective, it seems reasonable when the ultimate Jaeger weapon turns out to be a sword.
This approach requires you to be mindful. The fact of the matter is that a cannon can deliver a lot more energy than a Jaeger’s fist. Audiences are generally willing to ignore this discrepancy when it’s used to put brawling and sword fighting on par with or slightly better than guns. However, if you become overzealous with nerfing firearms, it will start to feel forced.
Another option is to introduce technology that discriminates against the higher velocity of projectiles. Dune has personal shields that deflect attacks with high kinetic energy. Forever War has fields placed over a battlefield that negate kinetic and electromagnetic energy. In both cases the setting is going a step past nerfing guns to take them out of the fight completely. This allows the story to progress as if guns aren’t a factor at all or as weapons that can only come into play if someone first disables the field generator.
The downside to this exotic technology is that it requires more set up and exposition for the audience to understand it. Anti-Kinetics change the rules of the game enough that your audience won’t be able to intuit what is and isn’t affected without you giving some background first.
3. Super Swords
You can create swords that are much more than a sharpened metal blade. In Warhammer 40,000 power swords are surrounded by an energy field that acts like a plasma cutter. Star Wars has lightsabers, blades of pure plasma. Both these super swords can slice through the strongest materials as if they were industrial strength cutting tools. Armor and barriers that are resistant to sustained punishment from gunfire are melted with ease.
Introducing super swords doesn’t solve the initial problem on its own, however. The super sword may be very effective, but unless you can survive long enough to close the distance, an opponent with a gun still wins. Armoring combatants against all but the strongest firearms and explosives is the method used in Warhammer 40,000. In Star Wars, Jedi are given super human perception and reaction time to deflect blaster fire, essentially using the sword as a shield.
4. Improved Agility
If nothing else fits, you can simply have characters skilled enough to avoid gunfire. Marvel’s Daredevil uses his speed and agility to stay ahead of where his opponent thinks he’ll be. In Cowboy Bebop, Vicious manages to avoid gunfire and fight Spike with a sword. Simply being too fast or agile to shoot is always an option in fiction.
When the characters fighting this way have special powers, it’s easy to get away with. Even without powered characters in your story, you might get a pass from some audience members who are used to the convention. But others may find it too unrealistic or gimmicky, so make sure to know who you’re writing for.
It’s definitely possible to make melee weapons feel relevant in a world with guns, lasers, tanks, and spaceships. You just need to create the conditions for it, and be aware of the implications of the technology. Be mindful of how your audience will perceive the technology you introduce and what elements they are willing to suspend disbelief for. Then when your hero brings a sword to a gunfight, everyone will see that they are making the smart choice.
P.S. Our bills are paid by our wonderful patrons. Could you chip in?