Basic Platformer Physics

Topics: Developer Forum
Jun 15, 2009 at 5:45 AM

I've been messing around with so many things today in Farseer (which I absolutely LOVE) and am just having a pain in the neck trying to get a good representation of the way the real world is. I'm really bad at finding what I need and have looked everywhere for help. I know how to use the UnitConverter now and have been using it to help implement realy world gravity. My biggest problem is though that I can't find a good conversion to go by. One source I found said he went by 1 meter = 50 pixels. I honestly found that to still look a little sluggish (spacelike gravity). I'm looking to get something that looks like how most games are done (ex. Braid, Sonic the Hedgehog, Mario, etc). If anyone can give me some good default things to go by, that would be FANTASTIC!!! I just need a step in the right direction before I go any further. Also any other good amounts for any of the physics are also greatly appreciated (friction, mass, whatever else there is in Farseer). Thanks to anyone who can help me out with this and sorry if this has already been discussed.

Jun 15, 2009 at 7:44 AM

I use a gravity of 1000, that works well for me.

As for the masses, you can use any values as long as theyre proportional to each other. eg: a 1 mass body colliding with a 2 mass body is the same as a 1000 mass body colliding with a 2000 mass body.

You can also use a density (eg: wood = 0.014 mass/pixel squared), and multiply it by the area of the geom to get the mass. Then you dont have to think up a new mass for every object.

For friction and bounce, just guess it. Eg: Rubber is sticky, high friction, so make it 1. It bounces too so make its restitution 0.9 or 1. Ice has no friction, so make it 0 or 0.1. And use 0.5 for things like wood, which are average. Thats just a start, keep adjusting as you go along because physics works differently in everyones game.

It takes a lot of tweaking to get it right(as everyone will tell you, with physics:D), which will always be different, there are no fixed values. Keeping things in proportion is good though.

Jun 15, 2009 at 12:33 PM

have a look at this thread: http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=56334

Jun 15, 2009 at 4:07 PM

thanks guys! very helpful for what i needed and everything. just one thing i'm wondering. is it best to leave all units in pixels or should i be doing a conversion from for example meters to pixels? i know this is more of a preference thing but i like hearing multiple opinions before i go out trying stuff.

Jun 15, 2009 at 5:55 PM

keep in mind that you can zoom in and out. under this circumstances a pixel looses every meaning and puffs into a cloud of logic.

Jun 16, 2009 at 4:22 PM

wouldn't that apply to zooming out as well. i mean lets say that i zoom out 50%. if we move by pixels we would still move a lot more because 10 pixels woudl then be like 20 pixels. now i was thinking about this and had an idea. could i just change the ConverUnits conversion by how much i'm zoomed out? oh and also i have never messed with zooming out so could you run that by me how to do it. all i can think of is scaling all objects down.