Public Group

# 2D Platformers - Rotating Platforms / Player Position

This topic is 2852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently working on a 2D platform game, much in the style of Super Mario.

I have a problem in implementing rotating platforms in my game, specifically when updating the position of my player when on a rotating platform.

I can get my character to stand on a rotating platform, and update his position so that he stays fixed on the platform as it rotates around a point of origin. However, when I try to move my player left or right on the platform, I encounter problems. Often, when moving in one direction, my player character will actually move backwards instead of forwards.

Every frame, I check to see if my player is standing on a rotating platform. If so, I fix his X Position to that of when he first made contact with the platform. This allows me to keep the player at the same position on the platform regardless of it's rotation around a point of origin.

In order to move my player, I update his velocity every frame.

I do not currently add the velocity of the platform itself to the player, as I have found that doing this does not work. When standing still, he will start moving around because of the platform's velocity, which is not what I want.

Does anyone have any suggestions on how I could rectify the problem?

##### Share on other sites
U have to calculate the position of your player in a hierarchical way. U can see the platform as the parent element of the player. Update your player's position in relative coordinates to the platform and not in global coordinates.

##### Share on other sites
^ That's actually what I do. When he first makes contact with the platform, I calculate his position relative to the platform and then alter the player's position by that value as the platform rotates. Thus, when standing still, he stays in the correct position relative to that platform as it rotates.

I want to keep my system of moving my player via a velocity model, as he needs to accelerate in a way that is consistent with his movement on the ground. However, it's the combination of fixing his position and applying velocity that does not seem to work.

##### Share on other sites
Hey,

I'm sure this isn't the answer you'd like to hear.. but have you considered implementing a proper physics system? It'll make it a lot easier in the long run..

Check out box2d (http://www.box2d.org)

Cheers,
Bach

##### Share on other sites
Quote:
 Original post by thebachHey,I'm sure this isn't the answer you'd like to hear.. but have you considered implementing a proper physics system? It'll make it a lot easier in the long run..Check out box2d (http://www.box2d.org)Cheers,Bach

I've looked at Box2D, and although it's a great physics engine, it's hard to alter it in the ways I would like. You often have to hack things and find workarounds in order to add custom behaviour.

##### Share on other sites
Hmm.. not sure what exactly you're trying to achieve but for something like "Super Mario" it seems like you'd want fairly realistic physics behaviour? Or not?

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002051
×