How do I set the position of a potentially moving body?

Sorry I'm very new to this. I simply want to set the position of a body. How do I do this?

Also, if the body is already moving, how would I stop it moving when I manually set it's position?
That's my problem too! 🙂

I guess that to you need to do:
-clear forces on a body
-set linear and angular velocity to zero
-set position of a body

However setting position of a body with setTransform doesn't work as moves the origin of a body, with its shapes staying in place. As a result, my ball starts rotating around a dislocated axis.edit: I looked again and it doesn't work this way; i recalled it wrongly.
Use SetTransform to move bodies and SetLinearVelocity to stop them from moving. If the body origin and the center of your ball are in the same place you will not have zxc's problem. You can do this by setting the starting position in the body def, not the shape:
Code:
bodyDef.position.Set( 12.3, 45.6 ); //body will start here
...
circleShape.m_p.Set(0,0); //circle is centered at body origin
@grantrobinson/@zxc
This worked for me.

1. Make the body type = "Static" (so that you'll be able to reposition the body)
2. Set the x/y coordinates
3. Call syncTransform() from the BodyShape class
4. Change the body type back to "Dynamic"

Code:
myBody.syncTransform()

[Update] You'll have to save force variables (linearVelocityX, etc) before you changed the position and then reapply. If you don't, you body will just fall according to gravity.

Johnny

Original thread: https://box2d.org/forum/viewtopic.php?t=7158