In Kingdom Hearts, we first meet Riku as a 15-year old. But chronologically speaking, the earliest scene he has shows him as a much younger boy. In this state, Riku is innocent.
He loves playing with his best friend Sora and, like most little boys, dreams of having adventures someday. In fact, the brilliance in showing Riku being so attached to the idea of leaving his island home for something more is that it's the exact type of motive most Disney heroes have. Ariel, Belle, Aladdin and Jasmine, Simba, Quasimodo, Hercules, Mulan, Tarzan...and even ones created later such as Wilbur Robinson, Rapunzel, Wreck-It Ralph and Moana. They all have this same quality: the desire for more, to broaden their horizons and satiate their curiosity or resolve their insecurity. Riku's fate is clear: he is to be a hero in this universe. In fact, Riku himself begins seeing the signs of this destiny that awaits him.
The problem is that while heroism may be in Riku's nature, nurture had other ideas. Growing up on the island, Riku trained and became strong, earning the admiration and praise of all the people around him. Being destined for greatness wasn't enough; now everyone was telling him how great he was. This not only feeds Riku's ego but also creates a direct dichotomy between his dream and his reality: while everything surrounding him gives him the impression that's he's the best, how can that be true when "everything surrounding him" is just a tiny part of a much larger whole that he's missing out on? In the grand scheme of things, Riku might not be so great after all, and that fear gnaws at his heart. What's worse: his best friend Sora, whom Riku has been like an older brother / protective leader figure to and whom Riku appears to be naturally better at everything than, seems pretty chill about his place in the world. To the point where Kairi, whom Riku sees as this magical living proof of a larger universe beyond Destiny Islands, gravitates more toward Sora and not Riku, the one who appreciates her more (or so he thinks). This makes Riku jealous of Sora, and this jealousy motivates him even more in his desire to explore other worlds and secure his heroic destiny.
While the Riku we are introduced to still has some of his old innocence in him, shown by his genuine care for his friends and desire to have them with him on his adventures, there is a darkness present too. He's not pursuing his goal for the right reasons. Kairi can sense this and it unnerves her...she can't quite place why, but something about it rings familiar to her.
The guy who is behind this sense of familiarity, Ansem, then ends up appearing to Riku and goading him into attempting to open the door in the Secret Place...the door to the world's heart. It doesn't work without the Keyblade, but it does alert the Heartless to the darkness in Riku's heart...and now they now exactly where their primary target, the world's heart, is.
Riku uses the darkness that invades the islands to escape to the outside world, and shortly afterwards Destiny Islands is destroyed. This is Riku's first villainous action, but I will cut him some slack here. Not only was he directly manipulated, but it's clear that he doesn't actually realize that what's happening will destroy his home. He seems to be under the impression that it's just destroying the barrier between Destiny Islands and the rest of the universe, allowing a pathway out for him and his friends. It's callous and it's reckless, but the magnitude of the destruction it's causing is something that Riku is oblivious to at this point in time.
When we next see Riku, he's already spent some time in the company of Maleficent and her assembly of Disney Villains gathered in Hollow Bastion, having been granted a sword by the sorceress and clearly having practiced fighting with it. Maleficent ultimately leads him to Sora in Traverse Town under the condition Riku not speak of her to him. During Riku's reunion with his best friend, Riku sees that Sora now wields the Keyblade - the weapon that was destined for him - and has been traveling around the universe having adventures alongside Donald and Goofy. This infuriates Riku. In his mind, this was supposed to be an adventure that he led. He would be the Keyblade wielder, traveling the universe and having adventures alongside Sora and Kairi. But not only has Sora now gotten the Keyblade and seemingly "replaced" him and Kairi with Donald and Goofy, but he is thriving. He doesn't need Riku's protection, he isn't falling short behind Riku...he isn't the same Sora that Riku knew on Destiny Islands. And because of Riku's aforementioned ego and pre-existing subconscious jealousy of Sora, this all makes him irrationally perceive Sora as having betrayed him.
While Maleficent is manipulating Riku, it's not in the same direct manner that Ansem did, and more to the point Riku should know better. He already knows that Maleficent and her gang are villains, as we later see he doesn't actually trust Maleficent one ounce. He clearly can see that Sora cares about him, as evidenced by Sora's relief to see him again and how he argues with Donald that Riku should join them on their adventure. And if he had so chosen, he could have stuck around long enough for Sora to relay what the Keyblade actually does, that it's more than just some shiny cool weapon and that it's needed to save worlds from the same kind of destruction that Riku unwittingly unleashed upon his home world. But Riku is arrogant, envious, entitled, wrathful...and above all, immature. In the greatest of ironies, despite Riku seeing himself as more grown-up than his peers and convincing himself that exploring other worlds and becoming a hero will help make him an adult, Riku's loss of innocence has only made him more childish than ever. He didn't get his way, and now he's throwing a tantrum.
At this point, Riku is done as an even remotely sympathetic character. Rejecting Sora as a friend, he now clings to Kairi as the only one he has left. And yes, he does still hold genuine care for her, but I feel like this misleads a lot of people from missing what Riku is actually doing here. He doesn't want to restore Kairi's heart primarily for her. He wants to do it primarily for himself. He knows how much Sora likes her, so now he wants to have her indebted to him so that she chooses him over Sora. Thus he can flaunt her to Sora like she's some kind of trophy. His line of thinking is "Oh, you think you're a bigshot now? You think you're better than me? Well, suck it! I've got your girl! Haha!" Again, it's highly immature, not to mention vindictive toward one of his friends and demeaningly objectifying toward another. Speaking of which, he also assaults a girl, knocking her unconscious and dragging her back to Hollow Bastion to be a prisoner in exchange for Maleficent revealing the location of Kairi's lifeless body to him. It's this act that cements that Riku isn't going to be a hero, but a villain.
Now, through all this we should remember that Sora and Riku's friendship was incredibly close. They are practically brothers. So it would be bad writing if Riku 100% turned against Sora this quickly. Thankfully, the game is better than that. When they next meet up within Monstro, Riku's goal is to manipulate Pinocchio and lure him toward the Parasite Cage Heartless. In the process of doing this, he taunts Sora and makes a game out of Sora chasing him and Pinocchio down. Maleficent astutely remarks that while Riku claims he's "just messing with him", it's obvious he still cares for Sora and that denying it will do him no favors. Afterwards, Riku attempts to vent his feelings honestly to Sora, then joins alongside him in fighting Parasite Cage to free Pinocchio. But afterwards, he takes Pinocchio (whom he assumes has gotten his heart devoured) away, even heartlessly rejecting the pleas of the boy's father Gepetto to give him back. This blatantly act of villainy comes back to bite Riku.
He gives Sora the offer to join him in using Pinocchio as an experiment to see if they can learn how to restore Kairi's heart. To get back to how things should be, with Sora following his lead, being the little brother figure stuck in his shadow. But unlike Riku, Sora is unwilling to sacrifice his conscience and is ready to fight Riku for Pinocchio. This doesn't happen, as Pinocchio ends up still having his heart after all and the Parasite Cage comes back to allow Riku a chance to escape. Riku is legitimately upset that Sora rejected him, but true to egotistical form refuses to consider if maybe he's the one to blame for this. As a result, he lets the possibility of repairing his friendship with Sora go and willingly lets Maleficent amplify the darkness in his heart so that he can control the Heartless. He then goes around on Captain Hook's ship, flying through worlds and having the Heartless destroy them in search of the remaining Princesses of Heart needed to open the way to Kingdom Hearts, where the knowledge on how to restore Kairi's heart can be gained. Let me stress: Riku is now intentionally doing to other worlds what he unintentionally did to his home world. His goal of "explore other worlds" has mutated into "destroy other worlds", and he's too far gone up his own ass to notice. As long as he says it's for Kairi, he can justify any atrocity he commits.
Off the coast of Neverland, Captain Hook captures Sora, Donald and Goofy, whom Riku has condemned to the brig...but not before turning Sora's shadow into a Heartless that does his bidding as a petty act of vengeance for Sora rejecting him. He is also revealed to have had a hand in kidnapping Wendy from Neverland, and when he learns she isn't a Princess of Heart, he coldly tells Hook to dump the "dead weight" into the ocean. Finally, after Sora and his friends escape from their imprisonment and make it to Hook's cabin, Riku uses a Corridor of Darkness to escape to Hollow Bastion along with Kairi's body...but only after directly siccing Anti-Sora on Sora, leaving him to possibly be killed. Riku is evil now...and he gets worse.
Maleficent then amplifies the darkness in Riku's heart again. The result is essentially turning Riku pure evil. After attacking the Beast while he's already badly weakened, he finally takes the Keyblade back from Sora and taunts him viciously. "Maleficent was right. You don't have what it takes to save Kairi. It's up to me. Only the Keyblade master can open the secret door and change the world. You were just the delivery boy. Sorry, your part's over now. Here - go play hero with this." And he tosses Sora a wooden sword, the same kind they played with on the islands. It's a truly cruel, demented way of saying "I'm the adult, you're the child, I am superior to you and I always will be!" And when Sora still resists? He tries to murder him.
This is the lowest that Riku can sink to. Trying to kill his former best friend, his brother, in cold blood. And for what? He doesn't even care about Kairi as a person anymore. All he truly wants is to prove his greatness by "opening the secret door and changing the world", as he put it. All of the selfishness, the entitlement, the darkness...it has completely consumed Riku. And this, along with the strength of Sora's heart that he showcases in a rousing speech, is why the Keyblade then leaves Riku, choosing Sora as its permanent master. After getting the ass-kicking he so richly deserves, Riku runs away like a coward, in complete shock and disbelief that after everything Sora still managed to beat him. That's when Ansem comes in and tells him that embracing all of his own heart's darkness isn't enough; Riku must open his heart up to darkness in general. He must become an avatar of darkness, just like Ansem.
And as I'm sure we all know, that last part ended up being way more literal than Riku bargained for. Ansem takes control of his body, and ultimately banishes Riku's heart, which holds his essence, out of the body entirely and into the Realm of Darkness. In short: Riku ends up damned and goes to Hell. In a grittier story, that would likely be the end of him.
In the Realm of Darkness, Riku...sees the light. There is now clarity in everything that has happened, everything that he's done, and everyone that he's hurt. And he is able to keep his heart alive out of sheer remorse and sheer determination to somehow right all that he has wronged....especially toward Sora and Kairi. Now, this does not automatically make Riku a sympathetic character or a hero. It's simply him finally realizing that he fucked up, and yeah, ya think!? But, it's still the all-important first step to bettering one's self. And almost as a form of good karma as a result, Mickey Mouse appears to take Riku under his guidance. Together, they help Sora (who defeats Ansem and thus grants Riku his physical body back) close the Door to the Realm of Darkness once it has opened, preventing an untold amount of Heartless from swarming into the Realm of Light. The universe will be saved...but it comes at a price.
Riku stays trapped in the Realm of Darkness, accepting his condemnation there as what he deserves, and being content to help Sora and tell him to take care of Kairi...an overdue acknowledgement that Sora's the one who truly loved her as a person and that thus her preference for Sora over him is rightfully earned. The Door of Darkness is closed on him, and that's the last we see of him. In accepting the negative consequences of his actions and acknowledging himself as a villain, Riku comes the closest he's ever been...to being a hero.
Tl;dr: Riku was a fantastic character in the original Kingdom Hearts because he was a negative one. His character arc was one of self-damnation, without sugarcoating anything. He was a good person in his childhood and a flawed but not altogether bad person when we meet him, but he becomes a worse and worse person as the game progresses through his own character flaws and willfully bad decisions. He's being manipulated, but he mostly isn't being misled. He's making stupid decisions, but he isn't making them unthinkingly. Riku is a complex and humanized villain, but he's not a sympathetic one since his evil actions and his reasonings for them go so increasingly beyond the pale of what can be sympathized with.
And this is also why he works so well in the following games.
Not only do we know how inexcusably evil Riku was in KH, but he knows how inexcusably evil he was too. Not only do we see him continue to express remorse for his sins and make genuine efforts to better himself and make amends even if it's at a direct cost to himself, he also directly tackles the reasons why he went down such a dark path to begin with. His ego is quickly cut down to size as he develops a more humble attitude, helped along greatly by Mickey's personality rubbing off on him. His insecurity about his place in the world and how it led him to destroy his home is confronted, and he determines that he must be the own to choose his own place in the world rather than desperately trying to prove what it is to himself and those around him. His ruthless desire for vengeance is reflected back at him by DiZ, and naturally he doesn't like what he sees. And he ends up flat-out admitting his past jealousy of Sora to Sora...which is after a long period of time where he prioritized Sora over himself, openly acknowledging him as the hero the universe needs. None of this would be as effective if Riku was just some poor, misguided soul in the first game like some fans pretend he was.
I think the techincal writing for Riku post KH has been hit and miss. I hate how overexposed Riku became as the franchise deuteragonist post KH2. I hate that Nomura made Riku "the true, officially ordained Keyblade Master" over Sora which goes against the whole original point. I hate how dull Riku's personality has become. And I hate Riku's current design. BUT in spite of all this, I still love and appreciate Riku on the whole. Because he's a prime example of a redemption arc done correctly - an evil person recognizes the harm they've caused and feel great remorse for it, stops doing bad and commits to doing good, and the good they do is wholly for the sake of helping others and doing what is right rather than for some kind of reward or self-benefit they feel entitled to. Other characters can learn from Riku's example.