Note that there are some explanatory texts on larger screens.

plurals
  1. PObox2d jittering when a body is magnetized
    text
    copied!<p>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:</p> <ol> <li>I subtract each bodie's position and screen center position - to get a direction to where i need to move my body to.</li> <li>Normalize the direction vector(which i've found in p.1)</li> <li>Multiply this normalized vector to my gravity power value</li> <li>Add the vector(that i've got in the p. 3) to the current bodie's speed</li> </ol> <p>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.</p> <p>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. </p> <p>I am new to box2d, and not very good with physics.</p> <p>What may also be important is that i set the bodies speed with the SetLinearVelocity method.</p> <p>Maybe i am just missing something, maybe there is some native for box2d way to achieve this. Any help appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload