FixedPrismaticJoint for moving platform not so fixed

Topics: Developer Forum, User Forum
Feb 4, 2013 at 1:17 AM
Edited Feb 5, 2013 at 5:03 AM
I'm having some trouble using FixedPrismaticJoint for moving platforms. They are oscillating on the axis properly but when the player interacts with the body, it gets pushed away while still oscillating. It's like the body is constrained to the axis of the joint but the joint is floating freely and subject to forces. Am I missing something to fix the prismatic joint relative to the world?

Here is a video of the issue in action: http://youtu.be/P0560ntb0hA

I'm creating the platforms like so:
prismJoint = new FixedPrismaticJoint(body, body.Position, new Vector2(1f,0));
prismJoint.LimitEnabled = true;
prismJoint.LowerLimit = -10;
prismJoint.UpperLimit = 10;
prismJoint.Enabled = true;
prismJoint.MotorEnabled = true;
prismJoint.MaxMotorForce = 1000;
prismJoint.MotorSpeed = 20;
world.AddJoint(prismJoint);
And updating it like so:
if (prismJoint.UpperLimit < prismJoint.JointTranslation)
{
    prismJoint.MotorSpeed = -speed;
}
else if (prismJoint.LowerLimit > prismJoint.JointTranslation)
{
    prismJoint.MotorSpeed = speed;
}
Any suggestions? Thank you.
Coordinator
Feb 10, 2013 at 3:54 PM
The fixed versions of the joints do have some cases where they do not work properly. Try with a non-fixed version that just uses the ground as the second body.
Feb 24, 2013 at 11:08 AM
Thanks for your response, Genbox. I replaced the FixedPrismaticJoint with a PrismaticJoint attaching the platform to a static body and had the sense to turn DebugView on. The platforms were still exhibiting the same behavior and the DebugView showed that the prismatic joint was not keeping the body constrained to the axis, whether I used PrismaticJoint or FixedPrismaticJoint.

I then realized the platform was a LoopShape and that I'd had trouble in the past with joints not working right when attached to loop shapes. I replaced it with a dynamic rectangular body and it now works as expected. I'm not sure why the LoopShape doesn't work here.