WeldJoints not working properly.

Mar 10, 2011 at 12:38 PM

In my game, one player plays as a fork and has to grab food that is passing by. I thought I could do this by creating a weld joint, and this seems to work well. However there is one problem. When I move and rotate the fork, sometimes the piece of food stops moving with the fork. The weldjoint is still there as the piece of food will stop in mid air until I release it.

The weird thing is, if I use a RevoluteJoint or a DistanceJoint, it works perfectly, but I can't rotate the object (since there's no constraint for that).

I uploaded a youtube illustrating the problem, since it's kinda hard to explain: http://www.youtube.com/watch?v=TycOtILs01k


I think it may have something to do with the amount of iterations I am stepping, as if I set the timestep to a very small number it works perfectly (albeit in slow motion). I know weld joints are not 100% rigid, but they should stay connected at least right?


Here's the code that I use to create the joint


// Create a joint between the collision spot and the food

WeldJointDef jointDef = new WeldJointDef();
jointDef.bodyA = fork.Physics.body;                    
jointDef.bodyB = shapeBody;                    
jointDef.collideConnected = true;                    
jointDef.localAnchorA = Vector2.Zero;                    
jointDef.localAnchorB = shapeBody.GetLocalPoint(fork.Physics.body.GetPosition());                    
jointDef.referenceAngle = shapeBody.GetAngle() - fork.Physics.body.GetAngle();
TheJoint = Universe.TheWorld.CreateJoint(jointDef);


The forks body is a static body and the food is a dynamic body with only one fixture. Has anyone had this problem before?

Mar 13, 2011 at 1:39 PM

Well, I got it working. Apparently the bodies were going to sleep when I was trying to move them. I turned off sleeping bodies and now it works fine =)