Pivot Joints and apparent elasticity

A rather disrespectful rant? Really? Compared to everything else that’s been posted on this thread?

I must’ve hit a nerve.

Goodbye, Mr. Ambassador. Have fun reaching the proper channels, and keep believing you’re relevant. I’ll be back in another 7 months when this thread is yet again revived from dormancy due to nothing having been done. [import]uid: 40137 topic_id: 3208 reply_id: 110792[/import]

(yawn)… hit a nerve? Believe whatever you want. :stuck_out_tongue:

We all eagerly await your glorious return. We’ll even roll out the red carpet for you, fanfare and all the rest. [import]uid: 9747 topic_id: 3208 reply_id: 110795[/import]

Easy fellas! Let’s take it down a notch…

@XenonBL, how about the following: I’ll send you my ported ragdoll project. At the same time, can you send me some code that shows how you are applying forces on bodies (preferably with similar property values)?

From what I can tell from non-Corona forums on Box2D with folks facing this issue, there is a stability issue. And typically, one small tweak in the parameter can make all the difference.

I should clarify that it’s not the force of the touch joint per se, but the amount of momentum that the touch joint gives the ragdoll *prior* to it colliding against another body (e.g. a wall). So if you are generating a tremendous impulse, then the collision could cause bad things to happen.

I’m playing with the Cocos2D ragdoll (https://github.com/YannickL/Box2D-Examples), and there’s joint separation there too for this very reason. The culprit is the same as what I was alluding to in my ragdoll project. If the touch joint is allowed to impart a huge amount of momentum, then there will be instability in the joints during a collision.

Cranking down the maxForce, implicitly cranks down the amount of momentum the ragdoll can have prior to a collision — and it’s minimizing that momentum makes it go away in *both* the Cocos2D and Corona projects.

Hopefully it makes more sense to you (and the rest of the folks here) why I’m so emphatic about trying to get some sort of test code from you, so I can understand how you are imparting momentum on your ragdoll *prior* to collision.

In the mean time, if folks have other *working* ragdoll examples, e.g. Flash or Cocos2D, that they recommend, please let me know. Thanks!
[import]uid: 26 topic_id: 3208 reply_id: 110796[/import]

I apologize to @iqsoup, @XenonBL, @walter, @fava, and everybody who has a legitimate reason for posting in this thread. Certain “tones” (mine included in this particular case) have no place in these typically mature, reasonable forums. Again, sorry about that. :slight_smile:

Brent Sorrentino
Ignis Design [import]uid: 9747 topic_id: 3208 reply_id: 110797[/import]

Sorry @XenonBL, but in my honest opinion, it’s pretty noob-sounding to start asking the co-founder and CEO of a software company not to require some form of working test case.

I’m not saying you are a noob or haven’t been in the biz for many years, but your point is noob sounding. That coming from someone who, also IMHO, is usually quite well written and thought out is a bit jarring to see here.

This thread has gotten quite nuts, but as has been pointed out - well, you don’t see Steve Ballmer making posts like these.

This next bit takes your post as a case in point but is general, because many similar things have been said in this and other threads…

You’ve said, “As far as I know I’m constructing my ragdoll…” - I think the point is that as far as anyone knows you are. Ansca doesn’t know any different unless you send them code. I have personally made this mistake and found it frustrating, but if you can’t reduce a single piece of code down to its core problem area then you can’t demonstrate the problem sufficiently. The developer’s argument breaks down if it appears that their entire program is broken. In proper modular coding the root problem code should be fairly simple to extract and believe me, I understand that might involve a lot of code. Enterprise web farms anyone? [import]uid: 8271 topic_id: 3208 reply_id: 110804[/import]

@Walter

Thank you for giving this issue some attention–its a big deal to a lot of us and its great to have some help.

Here’s a spinets of code that demonstrate one of the problems I’ve had with joints. I have many more but maybe we should take it one at a time. Maybe the solution to the below code will help me solve some of the other joint problems I’ve been facing.

--borders  
local borderLeft = display.newRect(\_W\*0.01, \_H\*(-1), 5, \_H\*4)  
borderLeft.alpha = 0  
physics.addBody(borderLeft, "static", {bounce=0.8})  
local borderRight = display.newRect(\_W\*0.99, \_H\*(-1), 5, \_H\*4)  
physics.addBody(borderRight, "static", {bounce=0.8})  
borderRight.alpha = 0  
  
--shape  
local randomShape = display.newImage(temp.imgpath)   
shapegroup:insert (randomShape)  
physics.addBody(randomShape)  
randomShape.x = math.random(\_W\*0.05,\_W\*0.95)  
randomShape.y = \_H\*(-0.5)  
randomShape:applyLinearImpulse(math.random(0,1),math.random(0,0.5),randomShape.x, randomShape.y)  
  
randomShape.shapeText = display.newImage("label.png")  
physics.addBody(randomShape.shapeText, { isSensor = true } )  
randomShape.shapeText.x = randomShape.x  
randomShape.shapeText.y = randomShape.y  
randomShape.myJoint1 = physics.newJoint( "weld", randomShape, randomShape.shapeText, randomShape.x, randomShape.y)  
  
--movement  
randomShape:rotate( math.random(1, 360) )  
  

Hopefully that’s enough to demonstrate what I’m doing. When the “shape” collides with a border there is a large bounce between the shape and its label even though the two objects are supposed to be welded together. I also have a rag-doll sample that has some major problems but it might take me a while to extract it from the rest of its code. I’m hoping a solution to the above problem might help me solve my ragdoll problems on my own. Again thank you for giving this issue your attention.

@IGNIS

Let me explain.

It is not Ansca’s job to write code specifically for me, but it 100% their job to deliver the product they promised. If I promised my clients one thing and sent them something else I wouldn’t get paid and you bet I’d lose the client. Any demands they made of me would be more than justified.

Don’t get me wrong, I quite like Corona and I’ve found Ansca staff to usually be more than friendly and helpful. Corona does most things very well. It even does most physics stuff fairly well–things like gravity, impulses…stuff like that. But one thing Corona just can’t do is joints.

One of my apps just used a simple weld joint and even that wouldn’t work properly. The welded objects would bump against a wall and there would be a large, noticeable bounce between the two objects. I had another app that I put a lot of work into–spent about 2 weeks created all the graphics I would end up needing. Before starting the project I looked into all the different joints and assumed it would be a walk in the park. This game relied heavily on using ragdoll-like objects. I, like everyone else whose tried, ran into some MAJOR problems. I spent who knows how long searching for a solution. I looked online and found little help. Eventually I found this forum and saw there were many others facing the exact same problem. I was frustrated that Ansca seemed to be ignoring the issue. I eventually gave up and scrapped that app. I wasted countless hours, days, even weeks because I thought Corona could do what it is supposed to do.

I hope that helps explain why this is such a major issue to me and why I’ve been frustrated by Ansca’s lack of attention. I’m very happy to see Walter get into this. [import]uid: 94309 topic_id: 3208 reply_id: 110805[/import]

Actually, I have in the past personally requested that I send my entire app to Ansca with as much security as they could provide to ensure that it didn’t get misused when I had a big, all-application-encompassing problem bug. This was because of a bug report I submitted which turned out not to be a Corona bug. Ansca took my whole game code and, I’m confident, deleted it after sending me an email explaining what I was doing wrong in my code. This, after I submitted a reduced test case which, unknownst to me at the time, was nothing to do with the actual problem. They also solved my problem and suggested overall improvements.

I’m not suggesting we all start doing that, but I am saying that Ansca’s team have been open to it and I think that says a lot. [import]uid: 8271 topic_id: 3208 reply_id: 110806[/import]

@iqsoup, can you send me (or post here) the code sample you used to demonstrate the breaking weld joint? I’ve not seen that problem and I use loads of them. Maybe I can help? [import]uid: 8271 topic_id: 3208 reply_id: 110808[/import]

Okay, so another long post, but I have found a solution that’s available in today’s Corona!

(1) Separation-free Ragdolls on other Box2D implementations.

First off, if anyone has a solid working example in Cocos2D, please send it my way.

As I mentioned previously, I have seen problems in alternative Box2D implementations including Cocos2D *and* Flash. I saw some assertion that this was unique to Corona, but I have not found a solid sample. Again, if there is one, I’d love to see what’s different about that setup. I have a feeling any working sample will do what I discuss in #3 below.

(2) Separation due to limitations of Box2D

Second, I found some relevant data about instability (i.e. separation) from 2 authoritative sources.

* From iforce2d (who’s clearly an expert on Box2D, given the number of excellent discussions on the site): You may get instability problems if you try to pull a heavy body with a lighter body.
* From Erin Catto: Chains of bodies connected by joints may stretch if a lighter body is supporting a heavier body. For example, a wrecking ball connect to a chain of light weight bodies may not be stable. Stability degrades as the mass ratio passes 10:1.

These both describe the sources of instability that I’m seeing. When you drag the ragdoll by the bicep, I’m able to get some instability. And this makes sense b/c you’ve got over 10 times the mass attached to it, i.e. the rest of the body attached to the relatively ligher mass of the bicep.

(3) A Solution!

Finally, I found a solution. Erin Catto (creator of Box2d) suggests on this thread (http://www.box2d.org/forum/viewtopic.php?f=3&t=1499) to turn off continuous physics for some guy having problems with pivot (prismatic) joints. So on a lark I tried turning it on:

physics.setContinuous( false )  

Voila! This seems to eliminate the instability and joint separation! If I crank up the maxForce on the touch joints (which seemed to exacerbate separation/instability under continuous physics), everything’s still fine. I also confirmed this by modifying the Cocos2D sample project as well. Again, no separation.

Okay, so what’s the catch? The catch is that continuous physics prevents objects from “tunnelling” where an object (e.g. a bullet) moves so quickly that it appears to move through a thin wall. Continuous physics prevents this, but there are apparently instability issues with joints. Turning it off makes the instability go away. However, you’ll want to make your static bodies extra thick to prevent tunneling effects

In my case, when I turned off continuous physics, I’d move the ragdoll so quickly, that half the ragdoll would be on one side of the wall and half would be on the other side — all because my walls were only 1 pixel thick! Making the walls 100 pixels thick prevented the tunneling.

So the trade-off seems to be: tunneling vs instability on joints.

Happy coding! [import]uid: 26 topic_id: 3208 reply_id: 110810[/import]

Thank you VERY much Walter. This seems to be the answer I’ve been looking for. I will try this out tomorrow and hopefully this can breath new life into a previously abandoned project. Thanks again! [import]uid: 94309 topic_id: 3208 reply_id: 110811[/import]

Wow, Walter, that is some seriously hard core debugging going on! Thank you and go get sleep, please! [import]uid: 8271 topic_id: 3208 reply_id: 110818[/import]

Walter,

Here’s a brilliant working example of box2D joints (albeit not a ragdoll).

(The 2nd example): http://www.emanueleferonato.com/2009/04/06/two-ways-to-make-box2d-cars/

Hope that helps.
Adam [import]uid: 74917 topic_id: 3208 reply_id: 110820[/import]

WOW!! BRAVO WALTER!!! That did the trick! There’s no separation of the pivot joints! Unbelievable after all this time. I was going to sleep after I saw your post but just tossed and turned and finally got up and added the line. In 10 seconds…voila indeed! The movement is slow but I probably just have to tweak some of the other parameters.
THANK YOU SO MUCH!! [import]uid: 40033 topic_id: 3208 reply_id: 110821[/import]

Ok, so a little testing, there’s a little separation here and there, the higher the gravity the more it happens, and it’s running slow, but I’ll keep tweaking. [import]uid: 40033 topic_id: 3208 reply_id: 110822[/import]

Hi Walter,

Thanks again, but I do have a question: setContinuous does not appear to be in the API documentation - is it or am I more tired than I thought?

Thanks,

Matt. [import]uid: 8271 topic_id: 3208 reply_id: 110823[/import]

D’oh! You’re right, it’s not there.

It will be in the new API docs. We hope to push that out next week. I did check, and the API has been available since last September, so should be available in the current public release.

@fava, my suggestions are to make sure:

(1) the two bodies overlap where you place your joint
(2) the densities “make sense” (you’ll have to do some tweaking)

BTW, setting continuous to false turns off additional calculations, so it should run faster than if you have continuous turned on. [import]uid: 26 topic_id: 3208 reply_id: 110830[/import]

Thanks again Walter, yes it’s working just fine! I’m so happy! :wink: [import]uid: 40033 topic_id: 3208 reply_id: 110846[/import]

Okay Walter:

Thank you very much for your solution. Ansca should give you a raise. You have been the only person at Ansca who have heard its customers.
I think that Ansca should have solved this problem at the beginning, not twenty months later than the first post.
As I published a video demonstrating the problem, this is a new video demonstrating the solution: http://www.youtube.com/watch?v=9HSJp8GJzCM

Congratulations, Walter. [import]uid: 140497 topic_id: 3208 reply_id: 110865[/import]

Walter, I’m so glad you finally cracked this one!

There is one more thing and i know this thread was about pivot joints and elasticity but i’ve got
a really big problem with pivot joint and wheel joint. I spent almost half a year trying to get this
to work. Submited the bug about 3 times…no replay… I asked on the forum several times…no one
could provide me the solution.

I also want to add that setting limits for WheelJoints don’t work at all.!

Can you just give it a quick look and see what could be wrong.

Here’s the video I made, explaining the problem and the sample code below.
http://www.youtube.com/watch?v=y1Jb14pUrwU

Thank you very much for your time and help!!!

display.setStatusBar( display.HiddenStatusBar )
local \_W=display.contentWidth;
local \_H=display.contentHeight;

local physics = require ("physics")
physics.start ()
physics.setScale( 60 )
physics.setDrawMode ("hybrid")

----OBJECTS
local legs = display.newRect(0,0,80,140);
legs.x, legs.y = \_W\*0.5, 860;

local body = display.newRect(0,0,160,300)
body.x, body.y = \_W\*0.5, 695;

----------------------------------------------------------
------------------------- ANCHORES -----------------------
---------------------------------------------------------- 
local anchor = display.newCircle(510, 500, 4); --Anchor above body's body

----------------------------------------------------------
------------------- PHYSICS BODIES -----------------------
----------------------------------------------------------
physics.addBody( anchor, "static");
physics.addBody( body, "dinamic" );
body.isSleepingAllowed = false;
physics.addBody( legs, "static");

----------------------------------------------------------
------- PHYSICS JOINTS BETWEEN ANCHOR AND BODIES --------
----------------------------------------------------------
local bodyWheelJoint = physics.newJoint("wheel", body, anchor, anchor.x, anchor.y, 1, 1);
bodyWheelJoint.isLimitEnabled = true;
bodyWheelJoint:setLimits( 100, 100 )

local bodyPivotJoint = physics.newJoint("pivot", legs, body, body.x, body.y+102 );
bodyPivotJoint.isLimitEnabled = true;
bodyPivotJoint:setRotationLimits( -30, 30 );

----------------------------------------------------------
------------------- ROTATE UPPER BODY --------------------
----------------------------------------------------------
local function rotatebody(e)
 local body = e.target;
 local phase = e.phase;
 local stage = display.getCurrentStage();

 if (phase == "began") then
 stage:setFocus(body, e.id);
 body.tempJoint = physics.newJoint("touch", body, e.x, e.y)
 body.tempJoint.dampingRatio = 0.8
 body.tempJoint.frequency = 400
 body.tempJoint.maxForce = 400

 elseif (phase == "moved") then
 body.tempJoint:setTarget(e.x, e.y);

 elseif (phase == "ended" or phase == "cancelled") then 
 stage:setFocus(body, nil);
 body.tempJoint:removeSelf();
 end
 return true
end
body:addEventListener("touch", rotatebody);

[import]uid: 77183 topic_id: 3208 reply_id: 110878[/import]

@optionniko, please start a new thread. I’d like folks to focus on the pivot issues here. I did take a quick look and can provide some recommendations on the new thread that you start. Thanks! [import]uid: 26 topic_id: 3208 reply_id: 110893[/import]