Jump to content
  • Advertisement
Sign in to follow this  
Storyyeller

platformer physics

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am attempting to make a 2d platformer. However, I've been having a lot of trouble with how to design the core physics mechanics. So far I've been dealing only with stationary platforms and I've got a mostly working system, but I have no clue how to extend this to moving platforms. Here are some of the issues I thought of. The first one looks tractable, but the rest look hopeless. -The player can stand on a moving platform and be moved with it. -The player can be crushed to death if two platforms move together with the player in between. -The player can be pushed off a platform by another platform. -Ideally, collision detection for the player can be handled polymorphically. (It probably won't use the same algorithms as other entities, but it would be nice to be able to treat it as another entity, because that would facilitate the addition of multiple players, or of monsters that utilize similar physics to the player, etc. and would also simplify the game loop. For example, I could have the character class keep a pointer to its current platform (when not airborne) so that it can get position updates in case the platform moves. However, this wouldn't explain how to make it get crushed. It also poses issues for serializing save files. I'm not sure how you'd save a pointer like that. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Don't reinvent the wheel, there are free 2d physics libraries to handle all of this for you in a fast/stable fashion.

For instance see :

http://www.box2d.org/

Good Luck!

-ddn

Share this post


Link to post
Share on other sites
Quote:

-The player can stand on a moving platform and be moved with it.


I may be wrong but I remember seeing various people posting how this was very difficult to do with box2d.

Quote:
It also poses issues for serializing save files. I'm not sure how you'd save a pointer like that.


this is probably why games have specific points you can save at?

alternatively you wouldn't save a pointer to the platform, but instead you'd save some kind of representation of what platform they are on, i.e. "Platform20" and then you'd have to be able to map that back to specific platforms in your game.

depending on how far you want to go you'd probably also want to save the state of the platforms x,y and direction etc.

in the end I'd just go for specific points to save from and reload the level from there.

as for moving platforms in general, if you can't find a 2d physics library that does it for you, i'd suggest considering creating the ability to lock >=2 objects together, perform movement for all objects based on the master objects velocity, then perform movement for all objects in the group individually.
i.e.
mario is on a platform
the platform moves 20pixels to the right
<something> signals to mario that his next will be +20pixels
however a platform is moving in the opposite direction his current platform
your collision detection determines that marios next movement will only be 1 pixel to the right because he can't go any further due to the moving platform
he falls off (at which time the lock must be undone)

if he was standing on a stationary platform and another platform comes along that would push him, you would just create a lock on them both and for every tick mario would be told that his new position has to 20pixels to the right, until the lock gets broken by mario going out of contact with the platform.

creating the lock would be based on your collision detection and determining when an object can do this (potentially you'd just create a lock for any target that is in the connects with a moving target, though you'd need a flag to signal what objects can and cannot be pushed).

as you can imagine, the more stuff you want to do, the more complicated something like that will get, so in the end a pre-made system will probably cause less stress.

Share this post


Link to post
Share on other sites
Well the trick is to make your character not a be controled by the physics engine. that way stuff like standing on a moving platform is simple. you just use the engine to detect collision of your character then react like u want to.

Share this post


Link to post
Share on other sites
Ok I'm going to try out Box2D to see if it works for me.

I think for the savefile issue, I'm just going to cheat and move the character up .1 pixels and set status to airborne.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!