Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2d Platformer physics [closed]

It was a long holiday weekend, so I got the coding bug again and started playing around:

Mario http://gfilter.net/junk/tileengine.jpg

I wrote a basic tile engine, but having never attempted this before, I am really struggling with handling sprite collision detection and implementing realistic physics for gravity.

For any other game hobby writers, can you point me towards some walkthroughs on the best way to approach this?

Update:

I thought I'd share a progress report:

http://www.youtube.com/watch?v=-RKNQ2UiiLY <-- Game in Action

Its still really buggy, but collision detection is mostly working, I've started working on some other features (such as bumping the blocks (notice the bug) and interacting with the enemies).

Mario still walks like he is on the moon, I'm using these constants, any advice for tweaking them for more realism?

    const float AirDrag = 1.00f;
    const float GroundFriction = .97f;
    const float Gravity = 0.8f;
like image 971
FlySwat Avatar asked Dec 01 '08 23:12

FlySwat


2 Answers

Download the FarseerPhysics engine, have a look at how it works http://www.codeplex.com/FarseerPhysics I think it's the best thing available for XNA/Silverlight!

like image 198
Tablet Avatar answered Dec 20 '22 21:12

Tablet


Gravity is easy:

const gravity = ... ; // pixels per timestep (eg. video frame) squared
// while in freefall, each timestep:
y_velocity += gravity;
y_pos += y_velocity;

Mind you, most 2d platform games I've played don't have realistic gravity. Just do whatever makes the game fun!

like image 43
Hugh Allen Avatar answered Dec 20 '22 21:12

Hugh Allen