rope simulation not working quite right (long)

This topic is 5067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi! (sorry long post) I'm currently working on a rope simulation for another piece of software and almost got it going, but i'm not sure if I implenting it using the ideal method. Current I'm using a variant of Nehe's method, where you have a rope 0----0----0-----0 where 0 = control point and ---- = Link between control points And I keep track of the Links between each control point. Then to simulate the rope I loop though the Links and use the standard Hooke's Law spring formulae as stated in Gamasutra's "Exploring Spring Model" My code looks something like this Pseudo Code
// Implementation 1

// Get the control points connected to this link

// Resets Forces
MASS1,APPLYFORCE ( 0 )
MASS2.APPLYFORCE ( 0 )

// Run the Hookes law caluclation
FORCE = CALCULATE_HOOKES_LAW(MASS1,MASS2)

// Apply force onto masses (using newtons third law)
MASS1.APPLYFORCE (  FORCE )
MASS2.APPLYFORCE ( -FORCE )

MASS1.APPLYFORCE ( GRAVITY )
MASS2.APPLYFORCE ( GRAVITY )

// Use euler method to position Masses
EULER_METHOD ( MASS1 )
EULER_METHOD ( MASS2 )

END LOOP

The above pseudo code works almost exactly how I want, the problem that's happening is that the Gravity is being applied twice on some masses ( because two links can share the same Control Point ), because of this, my rope control points become uneven and are closer towards each other at the end of the rope, as shown in this image: http://www.spot4d.co.uk/0x47/rope_hang.jpg This becomes a big problem when I have lots of Control Points (30+), the rope will stretch really long, even though I'm using a 100% stiffness in the Hookes Law algorithm. To solve this problem I tried another way to apply gravity Pseudo Code
// Implementation 2

// Get the control points connected to this link

// Resets Forces
MASS1,APPLYFORCE ( 0 )
MASS2.APPLYFORCE ( 0 )

// Run the Hookes law caluclation
FORCE = CALCULATE_HOOKES_LAW(MASS1,MASS2)

// Apply force onto masses (using newtons third law)
MASS1.APPLYFORCE (  FORCE )
MASS2.APPLYFORCE ( -FORCE )

END LOOP

LOOP THROUGH CONTROL_POINTS
CURRENT_CONTROL_POINT.APPLYFORCE ( GRAVITY )

EULER_METHOD ( CURRENT_CONTROL_POINT )
END LOOP

The result of the above snippet worked fine, all the control points were evenly spaced out as they hung due to gravity. But I neglected to mention that I can set any of the Control Points to act as an anchor, basically the EULER_METHOD is not called if the Control Point is flagged Anchor. If I anchored the Control Points at the start and end of the rope, the rope should curve in the middle due to gravity. Now here is my main problem after all that reading, if I use the orignal implementation (where gravity is applied twice on the control points) I get a correct curve on the rope, as shown in this image: http://www.spot4d.co.uk/0x47/rope_correct.jpg But as mentioned above I can't do it like this because the gravity applying twice causes problems. So if I use the second implementation, the simulation seems to ignore my anchored points, and hangs down regardless, as shown in this image: http://www.spot4d.co.uk/0x47/rope_problem.jpg As you can see, the rope hangs below the first control point and completely ignores the last control point. I don't understand why it is doing this I hope you managed to read it all :) and that I made myself clear Thanks for your help

Share on other sites
Why don't you add a flag to each control point that specifies whether gravity has been applied already? You then apply gravity only if it hasn't been applied, set the flag every time you apply it, and reset all the flags at the end of each frame.

Share on other sites
Thanks CoffeeMug.

To tell you the truth, I simply didn't think of doing that!

Well I tried it and it acts like it I want, so its working now

But I feel like this is a hack way of doing it, adding extra forces would result in adding more flags. For now I will do it like this so I can continue with other parts of my software, but I would really like to know if I was doing something wrong altogether

Share on other sites
It isn't a hack. You don't need to add a flag per force, only a flag per control point. Once you process the forces for each control point, you don't do it again in the same frame. Alternatively you could iterate through control points instead of iterating through links. It all depends on your simulation.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• Forum Statistics

• Total Topics
633370
• Total Posts
3011542
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!