4
\$\begingroup\$

I have implemented a 2D wire like the one described in this question which is made up of straight line segments between wrapping points. However, while the algorithms described in this answer work just fine for colliding with static geometry, it does not behave correctly when interacting with moving geometry. The method described in this answer does work correctly in some cases, but not when the rope does not move, since the collision detection method does not account for the movement of points.

How would you make the wire behave correctly when interacting with moving geometry?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ How does your engine move objects, move all then apply forces, move and resolve them one by one, or is it something different? \$\endgroup\$ Commented Aug 7, 2019 at 13:45
  • \$\begingroup\$ @trollingchar I am using Godot, which uses the Bullet physics engine. I am sadly not aware of how it works internally. I have updated the question. \$\endgroup\$
    – Encrylize
    Commented Aug 7, 2019 at 13:47

1 Answer 1

2
\$\begingroup\$

After calculating the rope, save the points it bends at relative to the objects, that cause that bend and the rotational direction (whether the rope bent in the right or the left direction). You can use these relative positions to reposition the rope during gameplay, but there will be 3 different interactions you need to pay attention to:

1.) An object hit the rope, so it should bend around it: This can be solved very easily using the same techniques you used during setup.

2.) An object stopped colliding with the rope: This very easy to solve, but a bit tricky to detect. This is why you need to save the bending direction at the beginning. If the rope bent around an object to the left, but it now bends to the right, that means that it got deattached from the object and you should merge the two segments

enter image description here

3.) The rope got shorter: Since the rope has to adapt to the moving objects, more of it has to be used to bend around parts. To solve this, take the last segment and shorten it. If it's not long enough, remove that segment and shorten the second to last and so on.

\$\endgroup\$
3
  • \$\begingroup\$ I have partially implemented this solution and have gotten step 2 working and step 1 partially working. The main issue is that the collision detection method that I'm using does not work if the rope has not moved, which is fine for static geometry, but causes issues for moving geometry, since it is now possible for rope collisions to occur without the rope actually moving. Any suggestions on how to fix this? \$\endgroup\$
    – Encrylize
    Commented Aug 10, 2019 at 15:48
  • \$\begingroup\$ A raycast along the span of each rope segment would function like a laser trip wire, and tell you when something has "interrupted the beam" that the rope now needs to bend around. \$\endgroup\$
    – DMGregory
    Commented Aug 10, 2019 at 15:54
  • \$\begingroup\$ @DMGregory, I have previously used raycasts for the collision detection, but found it to be suboptimal due to the rope being able to tunnel through points if it moved too fast. Additionally, I was unable to get it to work properly with moving geometry, since casting a ray along a rope segment would always result in a collision when both endpoints were colliding, which made it impossible to find the actual point that the rope would need to bend around. \$\endgroup\$
    – Encrylize
    Commented Aug 10, 2019 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .