I believe Nagato was actually goood, till the day Yahiko was killed, that changed him. You can still see how he loves Yahiko, reading the recent chapter, it seems the Yahiko body or God realm is a barrier type, now why would he give him that? Well to protect him. This is his way of redeeming his friend's death. By making the world share his pain, and using his body so he can show him he has accomplished his goals