# Platform physics in a platformer

This topic is 2237 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 not 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.

##### Share on other sites
And then I have to rewrite the entire object code from scratch, not to mention having to figure out how to get the physics library behave exactly the way I want (specially things like slopes and such). Physics should be more like old-school games rather than being realistically accurate.

Also for the record, it isn't very case-specific code, since all such solid objects end up would going through the same physics (this is object-against-platform physics I'm talking about). The difference in behavior between platforms and pushables is because platforms move on their own and are required to be synchronized so the way they move doesn't really respect physics for starters (that part is done in the object logic, not the physics code!).

I just asked for ideas to see if there's something I'm overlooking or if there's some better approach than the stuff I'm thinking I could do (still not decided on that).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015448
×