I want to create a body like b2CircleShape or b2PolygonShape for e.x. and use a joint to connect/stick it to the “ground” (screen?/world?), so that when I drag it with the mouse and release it, it gets dragged back to its original location by virtue of the joint.
Do I just create two bodies, one that is fixed in place and another that can move and create a joint between them?
Or do I connect the body to some kind of a “ground“?
So far I got this: http://jsfiddle.net/AP2D6/5/
I’m using Box2DWeb: http://code.google.com/p/box2dweb/
You could use a mouse joint or a motor joint to do this. The motor joint is a relatively new addition to Box2D so most likely is not in Box2DWeb yet.
To do it with a mouse joint, just do everything as you normally would for a ‘real’ mouse joint (ie. one that the player is actually controlling) except the target point does not move. You will need to set the maximum force for the ‘sticking to ground’ mouse joint to a weaker value than the one used to drag the body around, otherwise you wont be able to move it 🙂