Moving platforms - techniques and issues

Topics: User Forum
May 15, 2009 at 4:05 AM

I've recently implemented moving platforms into my game and for the most part, they work great. Below I'll describe the issues I've come across and maybe somebody can suggest something that I've not thought of yet.

Dynamic Bodies

At first I tried this approach (Body.IsStatic = false) as it seemed the right way to go, but I had trouble getting the platform to move to the correct location. It rotated and seemed to behave strangely when I manually updated the Body.Position, so I gave it a fixed angle joint and a revolute joint, but using FixedRevoluteJoint.SetAnchorPos() didn't move the body at all. I gave up on dynamic bodies, but if I can't get static bodies working correctly, I may have to go with some sort of force based controller applied to the dynamic body. Even if I do, they may exhibit the same problem as static bodies...

Static Bodies

At the moment I set Body.IsStatic to true and in my Update, use Body.Position = newPos. This works well, except when the platform is moving downwards, the player continually bounces as the platform leaves them behind and they fall to catch up. Another interesting point is that the PlayerBody.LinearVelocity == Zero whilst the platform is moving upwards. To try to work around this, I store the platform's last positon so I can calculate it's actual velocity. Then I use the player's collision/separation call backs to determine if they are standing on a moving platform. When they are, I set the player velocity to the platform velocity. This eliminated the bouncing issue nicely, but it seems like a hack (but then, doesn't everything ;)). So this leaves me with my current issue - Friction. When the platform is moving up, the friction is almost non existent. Maybe the player isn't actually touching the platform because his velocity is matched to it. When the platform is moving downwards, the friction is massive. I'm still trying to figure out a good fix for this, but I'm starting to wonder if I've taken the wrong path completely.

Any suggestions are welcome, and I'll post back here with any progress.

This is our dev blog for those interested: http://www.gnomicstudios.com/blog/

May 15, 2009 at 4:09 AM

making the platform static should work in most cases

what i did in my 2d platformer is make it that it would tie the enemy or players postion to be just about whereever the platform moves on the y axis
also this alowed the player to move left and right on the platform and when you jump it just went to normal physics

also any idea on how to make rope that dont strech in farseer?

May 15, 2009 at 4:18 AM

Cool, I'll investigate moving the position, good to hear someone got it working! See my reply to your other post.

May 15, 2009 at 4:45 AM

Hi danthekilla, I gave your suggestion a try, this is what I did:

  1. In player's OnCollision, determine relative Y position of player to moving platform
  2. In player's Update, if on a moving platform, update player's Y position relative to the platform's current y position

Unfortunately it didn't function that well - they player jerks around madly and falls through the platform. Can you expand on how you managed it? Maybe I missed something. I'd really appreciate it.

May 15, 2009 at 4:51 AM

it did take a lot of fiddling
i ended up with basicly setting the speed of the player to the speed of the thing he was standing on and (on the y) and turning off collsion reaction between the 2 and then you give the player the same speed as the platform moving down and i think i also moved his position each frame so he basicly moved with the platform and used the on seperate to detect the player jumping

now this all worked but my platforms move at a certian speed with pritty much no acceleration (it basicly gos up then down but just snaps to each no acceleration) also they are quite slow

it took me a bit of tweeking to get right thats for sure
just mess around with it for a bit