So i have some bodies(which i can create more and more at runtime), and i need them to be magnetized to the screen center. Let it be a (480/2 / WORLD_SCALE, 320/2 / WORLD_SCALE) in the world space. I am new to box2d so maybe there is an easy way to achieve this, but i am trying to do it as following:
- I subtract each bodie's position and screen center position - to get a direction to where i need to move my body to.
- Normalize the direction vector(which i've found in p.1)
- Multiply this normalized vector to my gravity power value
- Add the vector(that i've got in the p. 3) to the current bodie's speed
So after that i get what i want - bodies do magnetize to the screen center, i also add some frictions, and dampings so that bodies could ever stop. But, as i assume, because of my gravity vector to be constant length - i cannot force the bodies to stop moving completely. It always tries to move itself to the screen center and the smallest possible speed for them - is the length of this gravity vector.
If i only had one body, i would not perform steps 2,3 when the body is closer to the screen center then the gravity size is. But i can not bind bodie's position to the magnetic field center because the two bodies will never take the exact middle screen place since they will collide with each other. So i cannot make my gravity vector variable, and playing around with any frictions do not do the trick, maybe some step hack could help, but i think what i need is to implement some sort of bouncing counter force or something of that kind.
I am new to box2d, and not very good with physics.
What may also be important is that i set the bodies speed with the SetLinearVelocity method.
Maybe i am just missing something, maybe there is some native for box2d way to achieve this. Any help appreciated.