This project has moved and is read-only. For the latest updates, please go here.

Slider Joint without Rotation and Spring Questions

Nov 22, 2011 at 7:51 PM

I have been working with farseer for about a week now, and am very happy with it so far.  I have a couple of (hopefully) quick questions about joints.

1.  The slider joint seems to allow the bodies it connects to rotate freely.  To prevent this, should I add a second angle joint or is there another joint that will do the job of both?  I'd like the only relative motion between two bodies to be translations along the joint between them.

2.  I've seen some documentation about Springs from older versions, and understand they have since been removed.  Are there any examples, references, or suggestions that anyone can point me to?  I certainly remember my highschool physics F=kx, but that's about where I'll be starting to attempt implementing them.

Thanks in advance!

Nov 28, 2011 at 2:53 PM

To answer my first question: the prismatic joint doesn't allow any rotation between two bodies.  Think I actually played with this one a bit before posting, bug had a hard time with the factory's creation param.  The axis between the two bodies needs to be normalized, and the localAnchorB is the position relative to the second body that the first body slides along.  It's too bad there isn't an overload that takes both localAnchorA and localAnchorB like some of the other joints.  Having only one lead me to believe this was doing something else.  Here's what the overload would look like:

public static PrismaticJoint CreatePrismaticJoint(World world, Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB)
    Vector2 axis = (bodyB.Position + anchorB) - (bodyA.Position + anchorA);
    Vector2 localAnchorB = bodyA.Position - bodyB.Position + axis;
    return JointFactory.CreatePrismaticJoint(world, bodyA, bodyB, localAnchorB, axis);

Nov 28, 2011 at 4:34 PM

To answer my second question:

I'm now using distance joints with frequency and dampingRatio properties for linear compression springs:

I'm also using angle joints with softness and biasFactor properties for angular torsion springs:  I also use a revolute joint to pin these bodies together at the position of the spring.  I saw mention ( of using the revolute joint's motor properties to simulate spring forces, but haven't been successful in implementing this yet.

I'm not sure what the relationship between these properties and a more traditional spring stiffness constants are yet, but am interested in learning.  I'm also interested in hearing other approaches to implementing these kinds of springs with Farseer.