Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411468 Posts in 69368 Topics- by 58422 Members - Latest Member: daffodil_dev

April 23, 2024, 01:28:00 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Rope Simulation in Box2D
Pages: [1]
Print
Author Topic: Rope Simulation in Box2D  (Read 9456 times)
st33d
Guest
« on: July 14, 2010, 05:50:10 AM »

We're trying to simulate a fixed length rope. Any idea on how to do this?

I tried before to make a ball and chain in Box2D 2.0 by connecting a series of boxes with revolute joints. The result was quite springy and uncontrollable. The joints slid apart when they had a lot of centrifugal force put on them.

Any suggestions on how to go about making a rope like object that won't stretch?
Logged
raigan
Level 5
*****


View Profile
« Reply #1 on: July 14, 2010, 06:26:43 AM »

The only way I know of to make a rope that doesn't stretch is to cheat and solve the rope segments in order from the anchor/base end to the free/loose end, at each step fixing the parent link and moving only the child link.

To get this to work in Box2D you could e.g make a special "rope joint" which performed the above, but it might still be pulled apart if other joints are acting on the rope segments.
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #2 on: July 14, 2010, 12:15:47 PM »

i think it can be done through rotational joints between rectangles with fixed lower and upper angle limit.

This may help you
     http://www.emanueleferonato.com/2009/10/05/basic-box2d-rope/
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #3 on: July 16, 2010, 02:33:44 PM »

Box2D doesn't handle ropes brilliantly. But you are correct to use a chain of revolute joints. But there is a lot to tweak. Increase the iterations, to get more stability (at a high cost). Increase the mass of the rope, if it doesn't impact gameplay. Try using less links. Disable continuous physics. Increase the maxImpulse (or whatever it's called).

One trick I've seen work nicely, in the common case that heavy things are only at the ends of ropes, is an additional joint is put directly between the ends that constrains them to be at most the correct total length of the rope (distance joint can be fairly easily modified for this purpose). Thus when the rope is maximally extended, this extra constraint kicks in and takes off load, while appearing near identical. You can take this further than use an extra constraint for every n links, but I bet it ceases to be effective at some point.

Edit: I've never seens raigan's idea before but it sounds solid. One way joints in box2d are also very easy to hack in - find where it reads m_invMass and m_invI, and read in 0 for one of the bodies and voila. You need to be very careful with this though, as one way joints will also let you push stuff through walls.
« Last Edit: July 16, 2010, 02:41:54 PM by BorisTheBrave » Logged
Draknek
Level 6
*


"Alan Hazelden" for short


View Profile WWW
« Reply #4 on: July 16, 2010, 03:14:34 PM »

One trick I've seen work nicely, in the common case that heavy things are only at the ends of ropes, is an additional joint is put directly between the ends that constrains them to be at most the correct total length of the rope (distance joint can be fairly easily modified for this purpose). Thus when the rope is maximally extended, this extra constraint kicks in and takes off load, while appearing near identical. You can take this further than use an extra constraint for every n links, but I bet it ceases to be effective at some point.
That's clever, I like it.
Logged

ChevyRay
Guest
« Reply #5 on: July 18, 2010, 02:54:46 AM »

Amen, I'd never thought of that myself. I might actually use that very trick in an upcoming project. Thanks, Boris.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic