To answer your question, let's analyze killmonger to see what made him such a compelling villain. We can break down his character arc through three things: backstory, motivation, and consequences.
Let's talk backstory first. If you're trying to make a villain who the readers empathize with and relate to, backstory is an easy way to do so. Have your readers realize that they might react the same way as the villain had they had his same circumstances. For example, in Black Panther, Killmonger is told stories about the beauty and majesty of Wakanda. His father is a prince of Wakanda who decided that even though Wakanda was beautiful, it had faults and needed to reach out to the rest of the world. However, his father ultimately betrays Wakanda to their biggest enemy, but instead of doing something noble and heroic to stop the "villain", Wakanda kills his father and abandons him. Killmonger is forced to discover his father's lifeless body. He is forced to grow up alone in a poor part of Oakland, forced to understand that Wakanda doesn't care about him, that his own uncle killed his father. This trauma is etched into everything he does afterwards –every choice he makes is a direct result of his father's murder and his growing hatred of his motherland.
That leads us directly into motivation. What is Killmonger's motivation, and why does the audience almost agree with him? And where do his opinions differ from the hero's? It all boils down to motivation vs action. Let's compare his motivation with another character in the movie. Killmonger's motivation, at its core, is exactly how Nakia thinks. Both Nakia and Killmonger believe that Wakanda may be strong on its own, but it has a responsibility to the world to help out and offer its technology and intelligence. However, they differ in that Nakia is motivated by what she sees and what she does. She is already helping other people and saving lives, and she wants Wakanda to do more, while Killmonger is fueled primarily by anger and Wakanda's inaction to help him. It's personal to Killmonger. Making the motivation personal and fueled by revenge and hatred is a sure way of juxtaposing it with the similar but more righteous motivation. So although he and Nakia have the same goal in mind (Wakanda needs to help others), Killmonger wants to do so with violence and warfare. So, motivation = good and understandable, but actions = understandable but NOT justifiable.
Lastly, let's look at how T'Challa changes in response to Killmonger. T'Challa admits, by the end of the film, that Killmonger was partially right. Obviously, Nakia was more correct, but that doesn't change the fact that it took Killmonger's influence on T'Challa to change his perspective on his home. T'Challa was forced to understand two truths: 1) Wakanda needs to help others and 2) Wakanda/his father is not perfect. Through those two realizations, he is able to understand more deeply something he already learned in Civil War: "vengeance will not consume me." He is able to accept Killmonger's positive influence while also thoroughly disregarding Killmonger's weaknesses. Your hero/protagonist needs to change his perspective based on the antagonist's perspective. It's important that the antagonist permanently changes the protagonist's worldview.
Sorry for the long Black Panther analysis, but Killmonger is a great example of a great villain that perfectly reflects the protagonist's needs. His worldview is everything T'Challa needs to become a great leader –it helps him accept the sins of his father, it helps him fortify Wakanda, and it helps him reach the world. Your protagonist and antagonist should always be at odds, but ultimately, they must change each other.