I have been experimenting with changing the properties of a prismatic joint every time step to get a curved rail behavior. I figured there are too many kinds of curves to have a definition for them built into Box2D, so I gave the prismatic joint a callback class to allow the curve to be defined elsewhere. It works ok so I will share the code here.
The prismatic joint asks the callback for the info needed to define the current constraints, given the current position of anchor B relative to bodyA. If no callback is set the joint functions as normal. For the most part it seems ok but the limits can be a bit jittery, and it seems quite easy for two bodies on the rail to overlap, as if the joint constraint has a higher priority than the overlap correction constraint.
I also experimented with disabling the rotation constraint of the prismatic joint, by pretending that the rotation never needs correcting as suggested by Boris here
viewtopic.php?f=4&t=1267
This also seems to work well enough, until you put two of these joints between the same two bodies and then all hell breaks loose. It also bounces too much at the limits as well. I'm putting these issues down to the way the rotation correction is fudged.
Source: http://www.iforce2d.net/rail-callback-src.zip
YouTube video: http://youtu.be/hTCIRk9vcGA
The jittery movement at the limits could be a consequence of using an approximation for the translation, because it happens with the sine and spline curves but not with the circle which returns an exact translation...
The prismatic joint asks the callback for the info needed to define the current constraints, given the current position of anchor B relative to bodyA. If no callback is set the joint functions as normal. For the most part it seems ok but the limits can be a bit jittery, and it seems quite easy for two bodies on the rail to overlap, as if the joint constraint has a higher priority than the overlap correction constraint.
I also experimented with disabling the rotation constraint of the prismatic joint, by pretending that the rotation never needs correcting as suggested by Boris here
viewtopic.php?f=4&t=1267
This also seems to work well enough, until you put two of these joints between the same two bodies and then all hell breaks loose. It also bounces too much at the limits as well. I'm putting these issues down to the way the rotation correction is fudged.
Source: http://www.iforce2d.net/rail-callback-src.zip
YouTube video: http://youtu.be/hTCIRk9vcGA
The jittery movement at the limits could be a consequence of using an approximation for the translation, because it happens with the sine and spline curves but not with the circle which returns an exact translation...