How to make a moving object “stick” to a stationary object

Hello,

I am new to Box2D and have been experimenting with the box2D sample project within cocos2D for the iPhone and am wondering if box2D is the appropriate engine to use to make a moving object "stick" to a stationary object when the moving object is finished moving in a certain direction.

Here is a simplification of what I am trying to achieve: I have a dynamic body, MovingObject, that moves vertically against gravity when enough force is applied to it. As MovingObject moves, it may overlap a static object, StationaryObject. When gravity diminishes MovingObject's velocity to zero such that it is no longer moving, I would like to have MovingObject remain where it is ONLY if it overlaps StationaryObject. If the object's do not overlap, MovingObject should start to move back down towards the ground per the force of gravity. During that descent, if MovingObject at any time overlaps StationaryObject, it should stop its descent and remain in that location as if it is stuck on StationaryObject. The expectation is that during the upward trajectory of MovingObject, MovingObject would be overlapping StationaryObject most of the time.

I am able to get MovingObject to move per the forces I am applying to it, but not really sure how to make it stop and stay there once it reaches the top of its ascent, assuming it is overlapping StationaryObject. I've read various threads about disabling the world's gravity, but I still want gravity to apply.

Also, currently, I am experimenting with simple square/box objects but eventually both MovingObject StationaryObject will be defined as very different complex polygon shapes, in case that matters.

Thanks in advance for any insights and/or suggestions if this is achievable/appropriate in box2d.
If the MovingObject will not be bumped by anything after it has become stuck, you could just set its velocity to zero and thereafter cancel the gravity acting on it by applying a force equal to gravity in the up direction, every step.
If the object needs to interact/collide with other things while it is stuck, you could try a weld joint as mentioned in the manual, bearing in mind weld joints are not a perfectly fixed joint.

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