This project has moved. For the latest updates, please go here.

I can't get the Pin Joint to work...

Topics: User Forum
Jul 1, 2009 at 4:37 PM


First off, congratulations of the amazing engine! I've only been using it a few days and have learnt how to use a lot of it, but I just can't seem to get a pin joint to work. Here is my code:



public void NewObject(Body body1, Vector2 anchor1, Body body2, Vector2 anchor2, float distance)
          _pinJoints[_nextIndex] = JointFactory.Instance.CreatePinJoint(_physicsSimulator,
                 body1, body1.Position, body2, body2.Position);
          _pinJoints[_nextIndex].TargetDistance = distance;

with this calling it:

pinJoints.NewObject(rectangles.GetBody(0), rectangles.GetPosition(0), rectangles.GetBody(1), rectangles.GetPosition(1), 10);

When running the simulator view, the joint is drawn about 200f off in each direction, then the two rectangles burst off in different directions at high speeds with the joint going out of control and ending up off screen somewhere and sometimes coming back into view.

Can someone please tell me why this is happening and/or how to fix it. Thanks in advance!

Jul 1, 2009 at 4:41 PM

argument 3 and 5 are local positions and not world positions. They are the anchors on the bodies.

Instead of using body1.Position and body2.Position, try using 0 and 0. That will center the joint on the bodies.

Jul 1, 2009 at 4:44 PM

Thank you genbox!