A degree or two off course doesn't lead you wrong at first. At least, not too wrong that you can't self-correct.
But eventually that wrong course, that misaligned compass, leads one too far afield, and there's no way back to the place you thought you were going.
A misaligned moral compass can take your characters to interesting places, regardless of if you are writing heroes or anti-heroes. Of course, then one of the biggest challenges you have is making it clear that you, as the writer, are not advocating said moral failings. It's a story about a flawed person.
Take, for example, Ken Connell.
OK, it's not the most famous example, but roll with me.
Ken Connell was the main character of the flagship title of Marvel Comics's fascinating failure, The New Universe. The underlying concepts behind the New Universe were interesting, but much of the execution was disorganized and flawed.
The Star Brand was essentially combining Superman and Green Lantern into one concept: a tattoo-like power source that could be given to another, granting the owner incredible power only limited by his or her imagination. Possessed by the right man, it could be an incredible force for good.
Ken Connell is not the right man. But he really wants to believe that he is. He totally sees himself as a good guy who could do more and be great.
In other words, he's exactly the guy to buy into his own hero-destiny narrative.
In truth, Ken is kind of a loser. He works in a auto-repair shop, and is constantly talking about how much smarter he is than anyone else around him. He's got a lovely girlfriend who dotes on him, whom he consistently cheats on with a teenage girl who is so enamored of him that she happily slips out his back window in her underwear when his actual "girlfriend" shows up unannounced. (It's worth noting that he hides the StarBrand power from his girlfriend, but tells the teenager on the side all about it.)
He's that guy who is constantly complaining that life never gave him "his shot", but even with nigh-infinite power he doesn't do much to change his life. He does keep trying to do "good", in an abstract way, but he really isn't the good man he wants to think he is. When confronted with an "unstoppable" villain-- a soldier whose body has changed to be indestructible, and has decided to just walk into Russia and wreck the place*, Ken tries to do the "right" thing to stop him. But he can't stop him, so he just picks him up and flings him into space.
And also, Ken destroys the city of Pittsburgh. Not out of malice, but because he was too lazy to fly all the way to the moon to do an experiment with his power that he knew would be explosively dangerous.
But a lot of people believed that Ken was being presented as some sort of ideal, some sort of personal-avatar by then Editor-in-Chief at Marvel Jim Shooter. This mostly because Jim, like Ken, is tall and from Pittsburgh, and also because a lot of people did not like Jim and wanted to paint him in a bad light.**
The New Universe failed for a lot of reasons, but I think partly because audiences at that time weren't interested in "heroic" characters who were so flawed, so ordinary. It's funny, because plenty of stories like the New Universe and StarBrand have come up since.*** Characters who do the wrong thing for interesting reasons, and end up where they never wanted to be, and are only heroes in their own mind.
Ken is not a good guy, and is never presented as that. He never
understands that he's not the hero of the New Universe, but it's most
*- This was 1987.
**- In fact, having Ken destroy Pittsburgh was a decision made after Shooter was ousted, essentially a "Ha, we're having your hero destroy your city" pettiness.
***- Though, to be fair, with better overall execution and coherence of vision.