Using cocos2d and box2d , i have a few bodies that i need them to be attracted to each other, and a few others to reject one another. This means that when they are close the attract like magnet, or reject and pushed away.
Do i have to program it in the hard way (checking distance between them than applying forces when they are close) , or there is a simpler way for that ?
thanks a lot .
Yep. There is nothing built into Box2d (or cocos2d) currently to do this.
Edit
Pertaining to your comment:
It'll depend on how many bodies you have as to which technique you'll want to use. If you have a LOT of bodies, you might want to look at quad-trees to divide up your space and quickly ignore bodies that aren't close.
If you don't have that many, you can iterate your bodies in O(n^2) time with a naïve, but comparatively simple double for loop.
NB: This is by no means a complete solution, you should consider it pseudo code as it won't be compilable.