Logic to attach two objects via a rope

Hi all! I had an idea that i wanted to try implement in my app but not sure about the best way to go about it. I want to try and connect one object (lets call it A) to another object (lets call it B) by an invisible rope. A should then be able to drag B behind it. Both these objects have collision and B despite being dragged can also move around so if B were to get stuck or try and move away from A the rope should snap and the objects will be independent again. Ideally I’d like to avoid using actual physics in favour of a purely logic/mathematical approach. Problem is I kinda suck at math :sweat_smile: I’m going to continue to crack at it myself but would appreciate any help or advice you can provide. Thanks!

Edit: Decided to add a crude drawing of what I described above :slight_smile:

Probably you will need a physics helpers

Take a look at this post Recommended Physics Engine?

@JuanP Do you rate using a physics engine is the only way? Was aiming to avoid that if possible.

i made something like this and abstracted it into a component: Backdrop and cables - CodeSandbox the QuadraticBezierLine component still looks dodgy, not really a rope but gsimone made a better one that’s finished but not merged yet: things/README.md at main · gsimone/things · GitHub

catenary

as for snapping, you need something like cannon (physics). i only found a chain example, though that one doesn’t snap use-cannon/demo-Chain.tsx at 90dfc122945877b91f8d58700e3363e828a52d1b · pmndrs/use-cannon · GitHub