I'll try to teach you the easiest way.
Make an invisible sprite, bigger than your object, call it as "detector". Use platform, bullet or 8 ways behaviors here. Setup the gravity for 0 if using platform, so, it will hover and not fall.
Pin your object to your detector.
When the detector is overlapping the Ground Families (I strong recommend you use Families with all your ground and wall objects inside), maintain his direction in line, like you want (8ways behavior is the best for it, but bullet can work like a charm too).
The bigger your detector, high and far from walls your object will be.