Making a rope / chain

Official forum for the Chipmunk2D Physics Library.
darwinian
Posts: 3
Joined: Tue Nov 20, 2007 10:15 am
Contact:

Making a rope / chain

Post by darwinian »

I'm attempting to create a rope/chain object, but it is not behaving as I expected. I have a series of small bodies linked together by joints. Now if I hold one end of the rope fast, and apply a force to the opposite end to straighten it out, the bodies move apart and the joints appear to stretch between the them, rather than stay rigid as I would have expected. I have tried using pin joints and slide joints, and both suffer the same problem.

Any ideas what I could be doing wrong? Cheers.
X-0ut
Posts: 28
Joined: Tue Oct 02, 2007 5:02 am
Contact:

Re: Making a rope / chain

Post by X-0ut »

The documentation says slide joints are good for modelling a chain, but I got it working fine using pivots.
Basically I just had circle shapes for links with a body for each shape, and a pivot between each.
The pivot point goes on one of the links.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Making a rope / chain

Post by slembcke »

You're running up against the limitations of the constraint solver. The more of the following you do, the better:
  • Use more solver iterations.
  • Use a smaller timestep.
  • Put less force on the chain.
  • Put fewer bodies in the chain.
  • Use a constant timestep.
The first two items increase the CPU usage, the last two decrease it. You'll have to find a balance. If you aren't using a constant sized timestep, you really should be.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
citrys
Posts: 16
Joined: Thu Nov 15, 2007 12:26 am
Contact:

Re: Making a rope / chain

Post by citrys »

What's the practical difference between increasing the number of iterations for the solver (in Ruby, space.iterations) vs. stepping the space more frequently with a smaller timestep?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Making a rope / chain

Post by slembcke »

citrys wrote:What's the practical difference between increasing the number of iterations for the solver (in Ruby, space.iterations) vs. stepping the space more frequently with a smaller timestep?
That's a good question without a really good answer I think. Doubling the iterations or halving the timestep will not double the quality of the solution. Also, using a coarse timestep with a ton of iterations (or vice versa) doesn't really help either. In my experience, you have to find a good balance by experimenting.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
darwinian
Posts: 3
Joined: Tue Nov 20, 2007 10:15 am
Contact:

Re: Making a rope / chain

Post by darwinian »

Thanks for the responses.

After some more experimentation, I'm still not really able find an adequate solution. I am using a constant timestep of 180 steps per second, with ten solver iterations.

With only one joint, ie a rigid pole, the joint behaves fine, with a body of any mass swinging around on the end of it. As soon as an intermediate body is added (so that there are now two joints between the anchor point and the suspended mass), the joints will stretch. A solution to this is to reduce the mass of the suspended body, however it seems that the mass has to be reduced significantly (to roughly < 0.1) in order for the joint not to stretch.

Does this seem reasonable? I would have expected larger masses to still behave correctly.

Thanks again.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Making a rope / chain

Post by slembcke »

Ahh. So you are making a chain of really light objects and putting a heavy object on the end? That is a recipe for disaster in most physics libraries. Same problem with letting a really heavy object land on a light one. Because the light object has so little effect on the heavy one, it takes a lot of solver iterations to get a decent solution.

What I would recommend in this case is to even out the masses, or to use a single slide joint from the object to the anchor point and simulate the rope using vertlet physics. In the latter solution, the chain wouldn't be interactive, but it would look pretty at least.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Making a rope / chain

Post by dieterweb »

Hi,

Has anybody implemented the approach with vertlet physics for drawing a rope? It would be great if the one would share some code for this.

Thomas
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Making a rope / chain

Post by slembcke »

The code for simulating the physics (http://www.teknikus.dk/tj/gdc2001.htm) or code for drawing the rope?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Making a rope / chain

Post by dieterweb »

I already implemented it by myself.
But thanks for the link. Very useful site.


Thomas
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests