need advice for stretchable segment

Official forum for the Chipmunk2D Physics Library.
Post Reply
patrick
Posts: 1
Joined: Tue Aug 09, 2011 3:38 pm
Contact:

need advice for stretchable segment

Post by patrick »

I would like to create a series of circles connected by lines. The line lengths, however, should behave as damped spring constraints. Each segment has a circle at both ends. The segments must react to collisions with all circles other than the two at its ends.

Think of it as a stretchy chain that looks like ._._._._._._._
A bullet (.) that crosses this string should collide with it.

I know how to do this as a chain with fixed-length segments, but I need the segments to behave like damped springs. This is important because later I will connect the segments to create structures, and I need to control the spring constant so that the structures are rigid or soft.

How should I approach this in Chipmunk? I have two ideas, but not sure which approach to try first:

(1) Implement each line as a constraint that also reacts to collision detection.

or

(2) Implement each line as a stretchable segment body+shape that changes it's length based on the forces applied through the circle ends. Create a damped spring constraint between the circle ends to maintain the length of the segment.

Thoughts? What would be the simplest way to do this?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: need advice for stretchable segment

Post by slembcke »

Hmm. That won't be trivial, but I think the following would work.

For each link, you'll need a few things. Create the body at the position you want the circle to be and attach the circle at the center of gravity (no offset). Add a damped spring between the centers of the circles. Create a segment shape that extends from the center of gravity along the X or Y axis. ex from (0, 0) to (length, 0). To make the link's rotation work, attach a groove joint that extends along the same axis as the segment shape and attaches between circles. You can even set the groove anchors to set hard limits on the amount of stretch.

Each frame you'll need to update the length of the segment shape using the functions in the chipmunk_unsafe.h header. As long as nothing collides with the ends of the segments, you won't really run into any problems. Friction will act as though the link had the same velocity as the circle it's attached to, but that's pretty subtle.

I could attempt to make a drawing if that doesn't make any sense.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
crazynewidea
Posts: 1
Joined: Tue Aug 09, 2011 2:02 pm
Contact:

Re: need advice for stretchable segment

Post by crazynewidea »

Thanks for the advice. No picture neccessary -- your description was clear. I'll implement and let you know how it goes. The collisions with the segment will need to affect the attached circles as well. We'll see how it behaves once I find the appropriate functions in chipmunk_unsafe.h .
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests