# 2D Rope Collision Detection

I'm wanting to create a rope that can collide with objects like in the following youtube video:

2D Game Physics Rope

I'm thinking that you implement the verlet integration which uses points and connects these points with lines. I'm trying to figure out what type of collision detection you would apply to the rope to get the effect in the video.

I'm thinking you would have to do some cd to each point. I would like to use box2D, so I'm wondering would making each point a rigid body work? Any advice would be appreciated.

-
If you carefully watch the video in your link, it's clear that the "rope" being simulated is actually a chain, i.e. a large number of inflexible segments connected in a line, rather than a continuously flexible primitive. This is most obvious when the rope wraps around the small round obstacle; you can see the corners spin around it. A chain is much, much easier to simulate than a continuous rope; each link is just a collision primitive and they're permanently attached to each other. For more convincing behavior, make each link a very stiff spring rather than totally inflexible. – Paul Z Apr 21 '11 at 21:52

Since you're using Box2D, you can create a series of rectangles and use Box2D's joints to join them. There you have your rope.

In order to avoid corners poking out of a bent rope, I can imagine two options:

1. Give your rope segments rounded ends (so they won't be rectangles anymore)
2. Make this rope itself invisible and use it only for physics. Take the positions of the joints in each frame and use that to draw a rope on the fly that the player will see.

Warning: I have never tried this myself, but I fail to see how a series of joined rectangles can fail when the video you posted displays practically the same thing in disguise.

Edit: I just saw PaulZ and I realised the same thing. Go read his comment on the question as well.

-

A quick Google threw this up here. A demo, description and code (in Flash) using Box2D to implement a simple rope. The rope collides with itself and the block at the top of the scene.

-

Here is what I would do, make each each point on the line a circle, make enough points that the circles overlap. Tether each point to it's neighbour, rather than standard collision this tether should make the points stay a fixed distance from each other.

I don't know Box2D, but I'd guess the functionality required is there.

-

I remember this Allegro game: Cupid, from SpeedHack 2002. It contains an implementation for ropes that collide with the scenery. See PhysParticles and HeartTrails classes in heart_tails.cpp file in its source code.

-

Originally Box2D had a rope bridge demo made of thin boxes joined with point-to-point constraints; that would be a fine place to start (I don't know if it still ships with that demo, but it would be straightforward to recreate).

It's easy enough to implement rope as particles with distance constraints independently of a rigid body simulator (as you mention, using a Verlet integration and constraint solving scheme like the one described in this article: http://www.gamasutra.com/resource_guide/20030121/jacobson_pfv.htm), but if you want rigid bodies to react to your rope (like in the video, with the dangling box) then it gets much more complicated. I'd start with a comprehensive suite of tools like Box2D and work backwards rather then try and build up from particles.

-