Making sure I'm in good terms with peer researchers and not making enemies
Starting a collaboration comes with commitments. If you work together with someone, you cannot just walk away, because the other members of the team have invested a serious amount of work, which might depend on your contribution. So usually the only thing you could do is to finish the project and avoiding starting a new one. The latter might be difficult, because people trying to exploit you can prove quite clingy. However, as I read your question, you are in a easier situation:


  In addition, we found out recently that there are other papers that solve this problem or part of this problem in a very similar way.


Face it, your project is dead. You might get a publication by applying your method to some variation of the problem, but this is neither good science nor good for your career in the long run. So cut your losses and do something else. Ending the project can also be used as a pretext for ending the collaboration, which apparently did not work out.

While you are certainly right that scientists are as selfish and petty as everyone else, quite often both sides in such a conflict feel exploited by the other side. If you tell your collaborator every idea that comes to your mind, while s/he thinks things through before communicating, s/he will think that you leave all the hard work to him/her, while you will feel starved of necessary information. So a collaboration can end in a disaster, even if all people involved behaved exactly as they expected the others to behave.