I'm wanting to create a rope like animation effect. I don't need any kind of rope physics, all I need is a straight line connected to Object A and the other end connected to object B. Object A and B move relative to one another. So how do I make it so that the line is always attached to both Objects, even thought the distance between the objects decrease and increase?

The game is in 2D space.

  • \$\begingroup\$ You say it only needs to be straight while also saying it needs to contract and expand. Which is it? \$\endgroup\$ – Attackfarm Jan 15 '15 at 10:39
  • \$\begingroup\$ It only needs to be straight in the sense that it doesn't bend and is straight like an arrow. When is said contract and expand I meant it follows the harpoon as it goes up and down, but it isn't actually contracting and expanding, it just looks like it. Trying to make it simple: have you played the game goldminer? Thats what I need. A rope that acts like that rope, which is just a straight line that follows the claw object. \$\endgroup\$ – Sp3kk Jan 15 '15 at 15:57
  • \$\begingroup\$ So what are you trying and where are you getting stuck? Because it sounds like literally all you need is a black line. \$\endgroup\$ – Attackfarm Jan 16 '15 at 23:42
  • \$\begingroup\$ Yes, a black or preferably a brown line that is connected to object A and object B at all time. Even thought A and B move relative to one another in 2D space (Sideways & Up/Down). So I don't know how to keep the line connected to both A and B at all times, thats where I get stuck. \$\endgroup\$ – Sp3kk Jan 17 '15 at 10:49
  • \$\begingroup\$ You know what, I'll rephrase my question for simplicity. \$\endgroup\$ – Sp3kk Jan 17 '15 at 11:15

To draw a line:


To have it follow two points, simply keep track of the desired start and end points, and draw the line using those points for every update. In this specific circumstance, you would use the position of your two objects, something akin to this pseudocode:

Point start = objectA.position
Point end = objectB.position

drawLine(start.x, start.y, end.x, end.y)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.