James McAvoy has played the odd scoundrel, here and there. Think of his breakout turn in “The Last King of Scotland,” his fanatical cop in “Welcome to the Punch” or wily con man in the art world turn in “Trance.”

But in “Filth,” which opens May 30, his latest, he’s bad. Very bad.

“You get a chance, as an actor, to explore a side of yourself that you’ve never tapped into, to do things you’ve never done before, so there’s an educational payoff there,” he says. “It’s nice to surprise yourself, and that means you can surprise the audience as well.”

He plays a Scottish cop, Bruce Robertson — a sleazy, corrupt hedonist who never met a drink or a drug he didn’t want, never saw a comely female suspect or the willing wife of a friend or colleague he wouldn’t bed.

Unlimited Digital Access. $1 for 4 weeks.

“Filth,” based on an Irvine (“Trainspotting”) Welsh novel, is the sort of film “you’ll be scraping … out from under your fingernails for weeks,” critic Dave Calhoun wrote in Timeout London, praising the Scottish McAvoy’s “possessed … sheer caution-to-the-wind energy” in the leading role.

Bad boy Bruce is earning the 35-year-McAvoy some of his best notices ever. But the actor admits that he’s the sort of character that can spill over into an actor’s after-hours persona, and seep into other performances — say, McAvoy’s duties as the young Professor Charles Xavier in the long-running “X-Men” franchise.

“In the new (“X-Men: Days of Future Past,” which opens May 23) film, Charles is weirdly, insanely like Bruce Robertson in ‘Filth.’ He’s a cornered animal, spiteful, fearful, full of hate and anger. That’s not the Xavier we know. He has to work through that to become the sort of man who can help the X-Men win the day. It’s quite nice to be able to do that in this movie with all these externals — epic effects, action-based conflict. But there’s still this reflective side that lets us see this guy’s broken heart. That’s an interesting journey for a character to take.”

The lower-budget/limited release “Filth” is rolling into theaters as the blockbuster “X-Men: Days of Future Past” comes out, with the one threatening to utterly overwhelm any attention for the other. But as much as McAvoy declares his pleasure at “redefining Charles Xavier, not just back-engineering him from the Patrick Stewart performances,” his most fervent hope is that film buffs find the little film based on “the best script I’ve ever had the pleasure of reading” — “Filth.” Because Bruce Robertson is a narrator with a demonic wit and a character with demonic demons.

This “working-class, alcoholic drug-addicted Scottish policeman with mental health problems” could have easily been a “boring, kitchen-sink realistic, wise and informational movie,” McAvoy says. But writer-director Jon S. Baird has tapped into the “surreal, colorful, dynamic and funny” side of the novel, giving McAvoy an unforgettable character to play. Think of Robert Carlyle’s Begbie or Jonny Lee Miller’s Sick Boy from “Trainspotting.” Bruce Robertson would be a boon companion to either of them.

“We all have moments where we feel inferior to those around us. That’s one of the major things that drives Bruce. He’s this larger than life personality, sure. He’s all bluster, nobody’s better than him, and so forth. But that’s all in response to the fact that he’s got a raging inferiority complex and that he’s terrified that everybody around him is better than him. They’ll see he’s weak and take him down, you know?

“We’ve all felt like that, in times, in our lives. We don’t let them prevail, but we can’t help but have those feelings. We master that fear. His fear has mastered him, and it’s created this person who is constantly projecting this fake version of himself — all-powerful, content, confident — when actually he’s anything but that.”

After taking the character home with him during filming — “My wife was a bit shocked, and then perplexed by the guy I was while I was playing Bruce” — and maybe bringing some of his darkness to “Days of Future Past” — “I was constantly apologizing to the other members of the cast, even though they were probably up for a little abuse” — McAvoy was ready to leave the depravity behind. To cleanse the palate, he signed up for another potential blockbuster. Will he give the world a new mad scientist spin in the new “Frankenstein”?

“Finally! A Dr. Frankenstein with a Scots accent! The way he was meant to be played! The characterization that cinema audiences have been waiting for, for GENERATIONS.”

He laughs and admits that might be a tad too daring.

“Victor Von Frankenstein is English in it. He’s not from the Continent. He’s English, since the whole story is set in London, this time round. So I do my posh English accent. Alas.”