I have a cpSlideJoint constraint attached to two bodies to create a rope, which I retract by changing the max len (min len is zero). Gravity is applied to the hanging body, and the top body is a helicopter object with fixed y but slowly moving x.
It works alright, but when I retract it to shorter lengths it has a tendency to start windmilling (the hanging body will very quickly orbit the copter). I guess this happens because x velocity gets transformed to y due to the circular motion of the rope, and is amplified on rope shortening. Is there a way to apply some sort of moment of intertia like 'friction' to the copter/rope point of the slide joint, to make the rope lose more energy with each swing?
Wild spin with cpSlideJoint
-
- Posts: 2
- Joined: Sun Jul 07, 2013 4:45 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Wild spin with cpSlideJoint
How are you setting up the slide joints, and how are you modifying them?
If you didn't adjust the maxForce of the slide joint, it will be allowed to pull in with an infinite force. If you didn't set the maxBias, then when you change the length of the joint it will "pop" inwards quickly each time you do so (based on the errorBias property). I'd definitely recommend setting the maxBias to the same speed you reel the rope in at, and would also try setting the maxForce value even if it's something fairly high.
If you didn't adjust the maxForce of the slide joint, it will be allowed to pull in with an infinite force. If you didn't set the maxBias, then when you change the length of the joint it will "pop" inwards quickly each time you do so (based on the errorBias property). I'd definitely recommend setting the maxBias to the same speed you reel the rope in at, and would also try setting the maxForce value even if it's something fairly high.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 2
- Joined: Sun Jul 07, 2013 4:45 pm
- Contact:
Re: Wild spin with cpSlideJoint
I set up the slide joint by calling cpSlideJointNew with two non-static bodies, and min of zero and max of 200.slembcke wrote:How are you setting up the slide joints, and how are you modifying them?
I modify the joint by changing the maximum distance via cpSlideJointSetMax() in the update loop. I didn't modify maxForce/maxBias.
Later I add additional pin constraints to connect the hanging body to other bodies, but the behavior I describe applies to both cases (with additional hanging bodies or not).
I played with cpConstraintSetMaxForce/Bias, and the perpetual motion windmill effect seems to stop if I set the maxForce and maxBias to a low value, but it has the unwanted side effect of turning it into a elastic rope, like a bungie rope. I could not find a suitable middle ground in several attempts. Perhaps this is because it is not intuitive to me how to calculate maxBias which from the docs seems to be a speed of some sort. If it is a speed, what are the units (in 'x/sec' what is x?) I understand that elasticity is a side effect of maxBias limiting the amount of error that can be corrected in a frame.
Although it fixes the windmill effect, these changes didn't seem to add the kind of 'swing friction' that I was looking for either - is there a way to take out some energy from the swing each frame? So far the best thing I can think is just to apply a manual friction on v.x, but that seems pretty hacky.
Thanks for the pointers. I will continue to play with it, but if it looks like I'm missing something please tell me.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Wild spin with cpSlideJoint
The elasticity would be caused by setting too low of a maxForce than the maxBias. The maxBias value should simple be the same speed that you reel the rope in at. If you pull in 5 units/second, then set the maxBias to 5. It's the rate that the error (in this case, the extra distance along the joint's axis) corrected at.
As for slowing down the swinging motion, I suppose you could do that with an oddly configured pivot joint. Create the joint between the heli and hanging load with both anchors at (0, 0) so it doesn't cause any rotation effects. Set the maxBias to 0 so that it won't attempt to correct the position and pull the anchors back together (instead it will only apply to the velocity). Then set the maxForce to the amount of "friction" you want. When the two objects aren't moving together at the same speed the pivot joint will apply a force up to the maxForce to stop it.
As for slowing down the swinging motion, I suppose you could do that with an oddly configured pivot joint. Create the joint between the heli and hanging load with both anchors at (0, 0) so it doesn't cause any rotation effects. Set the maxBias to 0 so that it won't attempt to correct the position and pull the anchors back together (instead it will only apply to the velocity). Then set the maxForce to the amount of "friction" you want. When the two objects aren't moving together at the same speed the pivot joint will apply a force up to the maxForce to stop it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 9 guests