views:

3614

answers:

12
+8  Q: 

2d game physics?

Can anyone point me to a library for 2D game physics, etc for programming gravity, jumping actions, etc for a 2d platform/sidescrolling game ? Or could you suggest some algorithms for side scroller like mario, sonic etc?

+5  A: 

What platform are you looking for? What library you use will depend on this.

For the XNA framework, Farseer is pretty nice.

scubabbl
me looking for allegro+GCC combo
Abhishek Mishra
A: 

A general c++ lib to use in g++, but thanks anyways.

Abhishek Mishra
+17  A: 

It sounds like Chipmunk might meet your needs.

Ash Wilson
Oh, that is cool.
The Digital Gabeg
+2  A: 

You could look at the Havok engine. I believe they released a free version for non-commerical use. There is a constraint kit for it that will allow you to constrain the physics to 2 planes, in your case, x and y.

scubabbl
+2  A: 

The physics in most 2D side-scrolling platform games are so simple that you could easily implement them yourself. What kind of effects are you looking for?

Thomas
basically lots of dynamic jumps and bounces
Abhishek Mishra
+2  A: 

If you got the time you could use PhysX but its likely an over kill for 2D. Besides that if you plan on having your game work on a PC and want some cool physics, try googling for "verlet integration" I know there are quite a few verlet implementations around (nice for particles and 2D rag-dolls).

Robert Gould
+2  A: 

I've used Box2D in personal projects. It is a 2D physic simulation API. But, it might be overkill if what you want is more a game/graphic API.

bineteri
+10  A: 

Your best bet is most likely Box2D. It does 2D physics, has tons of options, and is very easy to integrate into an existing project. It does CCD by default for fixed bodies, but any rigid body can be selectively included in the CCD calculation.

Stephen Deken
i just love chipmunk and box2D thanks!
Abhishek Mishra
+6  A: 

If all you need is gravity, you can program that yourself in 5 minutes. Free-falling objects accelerate down at 9.8 meters per second per second - that is, an object's downward velocity increases by 9.8 meters per second of free-fall. For a game, you'll want to divide that 9.8 by whatever your frame rate is. For jumping, just pick a significant negative vertical velocity, apply that to the character at the instant they jump, and decrement it by your per-frame gravity increment. That's really all you need for something like Mario, unless you're looking for a 3d background for your 2d side scroller.

If you want to get fancier, you can try to take an object's impact force into account, making falling objects hurt people or crack pavement or something. For this, use the formula for Kinetic Energy: KE = 1/2 * M * V^2, where M is mass and V is velocity.

The Digital Gabeg
+2  A: 

This guy has done a lot of work with Javascript games:

http://blog.nihilogic.dk/

Ken Penn
+1  A: 

You can do 2d physics with opende as well

Florian Bösch
+4  A: 

To answer the second part of your question, if you want to get a handle on how a simple 2D platformer works, take a read through the tutorials for N. Yes, N is a flash-based game but that doesn't mean it isn't constructed like a "real" game, so the collision detection (and response) tutorials are very much applicable. They're a straightforward read with some intuitive demos embedded in the page to show off the geometric concepts.

bkane
you are right, libs like box2d, chipmunk are great but taking lots of time to implemnt and get used to. Since I am constrained to finish development by 28th, i need to reduce some game complexity, like possibility of uneven terrain and get to some simpler universally applicable methods rather than
Abhishek Mishra
...libraries and codes...
Abhishek Mishra
finally i made a game called nincompoop, it was to be finished by 30th september, so didn't give finishing touches - try here http://www.bidworkz.com/hfn/nincompoop_shaastra.zip
Abhishek Mishra