Implementing a wrapping wire (like the Worms Ninja Rope) in a 2D physics engine

Posted by Andrew Russell on Game Development See other posts from Game Development or by Andrew Russell
Published on 2010-07-16T02:25:32Z Indexed on 2012/09/12 21:51 UTC
Read the original article Hit count: 637

I've been trying out some rope-physics recently, and I've found that the "standard" solution - making a rope from a series of objects strung together with springs or joints - is unsatisfying. Especially when rope swinging is relevant to gameplay. I don't really care about a rope's ability to wrap up or sag (this can be faked for visuals anyway).

For gameplay, what is important is the ability for the rope to wrap around the environment and then subsequently unwrap. It doesn't even have to behave like rope - a "wire" made up of straight line segments would do. Here's an illustration:

This is very similar to the "Ninja Rope" from the game Worms.

Because I'm using a 2D physics engine - my environment is made up of 2D convex polygons. (Specifically I am using SAT in Farseer.)

So my question is this: How would you implement the "wrapping" effect?

It seems pretty obvious that the wire will be made up of a series of line segments that "split" and "join". And the final (active) segment of that line, where the moving object attaches, will be a fixed-length joint.

But what is the maths / algorithm involved for determining when and where the active line segment needs to be split? And when it needs to be joined with the previous segment?

(Previously this question also asked about doing this for a dynamic environment - I've decided to split that off into other questions.)

© Game Development or respective owner

Related posts about physics

Related posts about farseer-physics-engine