Abhishek Mishra
Abhishek Mishra

Reputation: 5040

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?

Upvotes: 11

Views: 17524

Answers (11)

Ash Wilson
Ash Wilson

Reputation: 24458

It sounds like Chipmunk might meet your needs.

Upvotes: 22

The Digital Gabeg
The Digital Gabeg

Reputation: 2785

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.

Upvotes: 9

bkane
bkane

Reputation: 969

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.

Upvotes: 4

Florian Bösch
Florian Bösch

Reputation: 27766

You can do 2d physics with opende as well

Upvotes: 2

Ken Penn
Ken Penn

Reputation: 766

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

http://blog.nihilogic.dk/

Upvotes: 2

Stephen Deken
Stephen Deken

Reputation: 3695

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.

Upvotes: 12

bineteri
bineteri

Reputation: 721

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.

Upvotes: 2

Robert Gould
Robert Gould

Reputation: 69825

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).

Upvotes: 2

Thomas
Thomas

Reputation: 181745

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?

Upvotes: 2

scubabbl
scubabbl

Reputation: 12797

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.

Upvotes: 2

scubabbl
scubabbl

Reputation: 12797

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

For the XNA framework, Farseer is pretty nice.

Upvotes: 5

Related Questions