A proper Rope

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Alex22
Prole
Posts: 26
Joined: Wed Jun 02, 2010 5:42 pm

A proper Rope

Post by Alex22 »

Greetings Lövers,
I've been trying to do a proper love.physics rope(not RopeJoint but a real rope) for some time now and still can't get it right.
I've already read several threads about this here, but none of them really helped me. Since they aren't about my main issue:
No matter what Joints I use (tried distance and ropeJoints) the first rope bodies will always act like they're elastic and lengthen if the force applied to it by the main body is too high.
A picture will make this clearer I think:

Image
As you maybe already saw here, not only the first Joint is being stretched, but also all the following ones, though the stretch isn't that obvious there.
(Note, that the the joint between body 1(in the center of the outlined circle) would also be stretched, but is is positioned each update at the center again to work against this)
Setting the mass to zero does not work sadly, and I can't think of any other way to work around this problem.


Use the left mouse button in the attached .love to create a circle and a rope between the ball on the ground.

Thanks in advance for any help <3
Attachments
physic.love
(3.01 KiB) Downloaded 222 times
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: A proper Rope

Post by Boolsheet »

I remember someone else asking a similiar or the same thing.
viewtopic.php?f=4&t=7689

I didn't look further into it after that.
Shallow indentations.
Alex22
Prole
Posts: 26
Joined: Wed Jun 02, 2010 5:42 pm

Re: A proper Rope

Post by Alex22 »

Boolsheet wrote:I remember someone else asking a similiar or the same thing.
viewtopic.php?f=4&t=7689

I didn't look further into it after that.
Yeah, I already read it, but he hasn't a solution either.
And the weird thing is, that this decreasing of the stability of joinst due to a too high mass ratio, isn't the problem since it doesn't work with all masses(but the main body) at zero.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: A proper Rope

Post by Boolsheet »

I don't know Box2D that well, but there are some things that caught my attention.

Setting the mass of a dynamic body to 0 (or lower) sets the body mass to 1. This is hardcoded into Box2D.
Don't set the body position every update. It seems to confuse Box2D and the simulation falls apart. The mouse joint can be used to have a body follow a certain position, but it was designed for the testbed and may not fit into your usecase. The manual mentions kinematic bodies, but I don't know how that would look like. Using its velocity to follow the mouse maybe...

I guess only a higher step count would increase the stability more.
Shallow indentations.
Alex22
Prole
Posts: 26
Joined: Wed Jun 02, 2010 5:42 pm

Re: A proper Rope

Post by Alex22 »

Boolsheet wrote:I don't know Box2D that well, but there are some things that caught my attention.

Setting the mass of a dynamic body to 0 (or lower) sets the body mass to 1. This is hardcoded into Box2D.
Don't set the body position every update. It seems to confuse Box2D and the simulation falls apart. The mouse joint can be used to have a body follow a certain position, but it was designed for the testbed and may not fit into your usecase. The manual mentions kinematic bodies, but I don't know how that would look like. Using its velocity to follow the mouse maybe...

I guess only a higher step count would increase the stability more.
If I won't force the body position of both the main body and the first rope body to a specified position, the whole rope goes crazy and seems to just fall down. The same with MouseJoints.

Isn't there a way to just force box2d to maintain a fixed length between the bodies, no matter what?
monkyyy
Citizen
Posts: 52
Joined: Fri Mar 16, 2012 5:29 pm

Re: A proper Rope

Post by monkyyy »

"Isn't there a way to just force box2d to maintain a fixed length between the bodies, no matter what?"

u could just "teleport" the bodys every frame, i think u'll quickly find why the box2d doesnt do this

i would try limiting to max speed of the ball locked to the mouse or up'ing the step count when ever the distance of the joints go above 105% of what it should be

edit//

u REALLY need to comment ur code, but that said adding these two parts of code did nearly fix the problem

Code: Select all

  world:update(dt/3)
   world:update(dt/3)
    world:update(dt/3)

Code: Select all

			speedreduction=3
			newx =bodyX+xdist/speedreduction  --TODO replace w/ better math
			newy =bodyY+ydist/speedreduction
			lastbody:setPosition(newx,newy)
and both are really hamfisted fixes that im sure u can improve on
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: A proper Rope

Post by juno »

If you increase the value of setMeter to a higher value...say 500, the problem seems to be less evident..hope this helps :)
wat ya mean she's in another castle!?
Alex22
Prole
Posts: 26
Joined: Wed Jun 02, 2010 5:42 pm

Re: A proper Rope

Post by Alex22 »

monkyyy wrote:

Code: Select all

  world:update(dt/3)
   world:update(dt/3)
    world:update(dt/3)
That bit of code actually really helped, when using 12+ segments it still gets worse, but not as much as when not using your code, thanks for that <3

The second one did also work quite well, but I rather stay with using the linearVelocity since it makes the movements quite more lövely.
juno wrote:If you increase the value of setMeter to a higher value...say 500, the problem seems to be less evident..hope this helps :)
Increasing the setMeter value actually helps, but also makes movements really unrealistic and fast, so thats no real option >:
But thanks anyway!
monkyyy
Citizen
Posts: 52
Joined: Fri Mar 16, 2012 5:29 pm

Re: A proper Rope

Post by monkyyy »

Alex22 wrote: That bit of code actually really helped, when using 12+ segments it still gets worse, but not as much as when not using your code, thanks for that <3
i would not use that code unmodified, like i said, it needs to be improved on, it wont scale at all, and would probably be completely worthless at 15+ seg's

something like

Code: Select all

 if"this code needed"
then magicly get a x value on how much it is needed
loop " world:update(dt/x)" x times
end
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests