# Platform physics in a platformer

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

## Recommended Posts

For those who are making platformers: how do you handle physics for platforms? I mean those that are objects rather than being part of the map itself so they have to be handled differently. The same question also applies to any object that has solid collision. I currently have some platform code up running but I want to know what other approaches are there because I'm having issues with anything that isn't a standard platform, and maybe I could get some idea that way.

In case somebody wonders, I'm asking about what kind of algorithms you use (no need for posting code, just an idea about how they work). Feel free to assume all such objects are axis-aligned rectangles if needed.

##### Share on other sites
I am currently writing a platformer as well. But, I haven't had any issues so far.

Out of interest, what sort of problems are you having? And how have you handled the actual platforms (ie. are they boxes, slopes, etc?)?

##### Share on other sites
The code works fine for normal platforms, but I have solid objects like pushable rocks and such that do [i]not[/i] work correctly (e.g. they can't push each other, or carried objects move at the wrong speed, etc.), not to mention code for walls and such still isn't implemented (only collision from the top).

As for platforms, they're just axis-aligned rectangles =P (the hitbox of the object - with one caveat, if the height of the hitbox is less than 1 then the platform is considered tangible only from the top, but that's just a matter of ignoring collision from the other sides)

PS: in case you wonder how moving platforms can carry objects at the proper speed and pushables can't... probably it's because the way speed is handled is different between them (since platforms are synchronized with the global timer and move using the sin() function so speed is faked by just calculating the current and previous values completely ignoring subpixel precision, while pushables have actual physics with proper speed and gravity).

##### Share on other sites
I'm not entirely certain what part you're having trouble with, but have you considered using a pre-existing physics library? It sounds like you're writing a lot of case-specific code, and I think using a physics library might help to reduce that and probably speed up your coding process.