Limit distance between two objects

Hi guys,

I have a scene where I want one object (Obj1) to follow another (Obj2), from above, as the object that is being followed is moving left (or right). However, I want the object above to have a limit as to how close it can get. I have solved this by adding a line of sprites horizontally with physics automatism set to Static (that are hidden), and also adding the physics automatism to the object above, so that it stops whenever it comes in contact with the “barrier”. Then I’m simply using a Move obj1 to obj2 with force of x pixels if distance is >=x.

It kind of works, but it’s not perfect, and it’s like the object above is shaking, escpecially when it comes to a stop (when the object below stops moving, probably because it is still trying to get closer to it, but the barrier is stopping it).

I have a feeling it would be better to use som y and x position test instead of the physics and barriers, but I’m not sure how to create it?

I have managed to limit the y position of other objects, but the question is basically how to do it relative to other objects.

I imagine a condition similar to “The Y position of Obj1 > Obj2.y(x)” → Action “Add a force as to move to a position Obj2.x(-xx) and Obj2.y(-xx)” to get Obj1 to move toward Obj2 but stop when position xx is reached.

What a terrible explanation. Probably easier to look at the screenshot… :stuck_out_tongue:


Edit: Solved.