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

Moving Platform

Jan 29, 2009 at 11:24 AM
Would anyone have any ideas on how to create a moving platform like that is seen in most 2D sidescrollers? Ultimately, i'd like a platform that could follow an irregular path.

Would the path example be of any use to this? I tried looking at the demo that has something like a tank tread, but I couldn't figure out how to attach my own bodies and geom to a path, and move it along the path.
Jan 29, 2009 at 1:27 PM
The path example shows how to create objects along a path, not move them.

Someone else may need to confirm this as a solution, but you may want to try a FixedRevoluteJoint.  Each update, move the joint's world anchor point along the path. (You'd have to determine the coordinates yourself.) The platform should have a MomentOfInertia of float.PositiveInfinity also, so it doesn't rotate.

If that doesn't work quite right, you could try a FixedLinearSpring in the same way.
Jan 30, 2009 at 10:48 AM
well what you could do is define a path via a Curve class or two and use that to store the positions for the platform, and use a FixedLinearSpring to keep it on that path. Not sure if this will work but if it does it would easily let you make platforms that follow irregular paths.
Jan 30, 2009 at 11:48 AM
I got it working using the fixedlinearspring, Thanks! Turns out the solution I used was fairly similar to the climble rope problem I posted about previously.

I used a list of vector2's to store the path the platform should take, then by using vector2.lerp I interpolate a path between the two points the platform is moving in currently, and move the fixedlinearspring's worldattachpoint appropriately. I had to use 3 (2 at the least) fixedlinearsprings to keep the platform steady, and a fixedanglejoint to keep the platform from rotating all over the place.
Jan 31, 2009 at 5:33 AM
Edited Jan 31, 2009 at 5:36 AM
Great! Did setting the MomentOfInertia to infinity work? also, if you use Curves, you can get smoother paths (i'm guessing that it doesnt have any smooth transitions betweeen path sectons right now?).
Jan 31, 2009 at 7:31 AM
I didn't set the MOI because I used a fixedanglejoint instead. Should I have it set to +inf anyway? I just tried setting it now, but I notice no difference. Transitions are fairly smooth, true, there's a very very slight judder like you get with a cable-car, but i'm happy with how it works for now. But yeah, paths are limited to straight line segments with this solution.
Jan 31, 2009 at 9:21 AM
hmm... is there any specific reason you're using a fixed angle joint? if there isnt then maybe you should just use the MOI (for performance b/c it's one less joint to update). Also, if you're planning on putting heavy stuff on the platform then you might need to find some other method of supporting it...