Advertisement

2d Physics

Started by May 12, 2013 01:37 PM
6 comments, last by white_waluigi 11 years, 9 months ago

i started to make a 2d game a while ago and i encountered a lot of Problem with movment and gravitation.

I managed to make sure, that stuff can't get through walls (Line-Collision System, with the Separating axis T.) But after that the Problems started and i desparating right now. first i had the Problem with tzhe Gravitation, that when you stand on a inclined line and Gravity is on, the Player slowly slides of the surfaces. also if you move on an inclined line you are slower than you were on even surface. next Problem is, that if you move in the opposite direction of an inclined line, you just fly in the air for a brief second. There are a lot of other Problems but i don't wanna list them all here.

Does someone have a few links for me?

http://box2d.googlecode.com/files/Tonge_Richard_PhysicsForGame.pdf

http://code.google.com/p/box2d/downloads/list

Advertisement

thx

OK, now I've looked through that stuff and it didn't really solve my Problem.

Maybe i should have mentioned that i wasn't searching for real physics like stuff rotating and rag-dolls and such, just Physics like in Super Mario for example (I know it says a lot, if i can't even get that right) just instead of simple Block-Worlds Worlds that are Physical build out of Simple Lines.

But the Problems are still with Gravitation.

Does maybe someone have some Tips or an OpenS Game to check how they solved it?

You might be better off implementing this yourself if you are looking for simple physics with no advanced features and existing tools are too hard to integrate in your game. Though for that you'll need at least some working knowledge about Newtonian mechanics (just translation, since you said you don't need rotation). Can you describe why someone standing on a frictionless slope will slowly slide down due to gravity?


For your first problem, if you want to prevent the player from sliding off a slope, you need to add friction. As I said, you would slide down a slope in real life if it were frictionless (think an icy slope). The most basic implementation is simply as follows (this is called static friction, there are other types of friction):

1. calculate the force the player exerts to move, call if F

2. calculate the force exerted by the player on the surface on which he is standing (gravity), call it N

3. if F > N * c, move the player, else, don't move the player, where c is some constant between 0 and 1 (called the friction coefficient)

This way, if a player simply stands on a slope, he won't move. And if he wants to move, he will be able to.

For your second problem, this isn't really a problem per se. If you walked straight off a slope in real life, you would fall and tumble as well. But what we do in real life is we follow the slope, that is, we incline ourselves so that we don't walk off the slope horizontally, but instead move diagonally along the slope. To do this, you can look at what the player is currently standing on, calculate the gradient at that position, and make the player move according to that gradient. This will make him "slide" down the slope nicely instead of moving in a staircase pattern.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

k, didn't think i'd have to go so far for a 2d game, but ok, thanks. So ill have to implement a system, that gets the surface(s) the player is standing on.

Advertisement

k, didn't think i'd have to go so far for a 2d game, but ok, thanks. So ill have to implement a system, that gets the surface(s) the player is standing on.

Well there are always ways to fake it. But if you want to make sure everything works as planned, it's best to have some code that can handle anything you throw at it (within the limits of your game). Otherwise you'll be piling hack on hack, adding one special case after another, and it gets ugly really quickly.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Otherwise you'll be piling hack on hack, adding one special case after another, and it gets ugly really quickly.

yeah been there already. Lost a lot of time. Now i wanna do it right.

So what do you think of that:

-a friction System like the one from Bacterius

-When a collision gets solved, that collision gets stored in the Units collision List. If the collsion was not too steep, the Player is allowed to jump.

I just wanna ask before i loose more time.

This topic is closed to new replies.

Advertisement