Rail Joint (Another Box2D custom joint)

Hey all, having spent a couple hours tonight trying to make a ‘fixed train’ in Aedifico for the story mode I thought it would be better to make it in to a class. I made a thread quite a while ago which featured this video in it somewhere:

I was hoping for it to be implemented as a joint in Codea but it’s possible to do with Codea itself so here it is:

Code: http://pastebin.com/kUqtZBpg

To use the rail joint pass the init function a set of points and bodies, all you have to do then put jointvariable:draw() in the draw function in order to keep the forces updated.

I hope someone finds a use for this, I’m going to be looking in to a pulley joint next and hopefully will be able to make a small library of custom box2D joints for the forum in good time.

Edit: forgot to mention as seen around the 0:40 mark there is a bug with the algorithm when rails overlap, this could be a desired effect in some scenarios though.

@Luatee Nice job. I was looking at the rail joint in a box 2D example somewhere and was thinking that if it ever showed up in Codea I could make a train. I’ll have to look at your code. I’m not sure about the glitch at :40 .

This is great! =D>


That’s really neat @Luatee, thank you for sharing.