Page 1 of 2

character movement physics

Posted: Sun Nov 22, 2009 6:53 am
by The Burrito
So, I've seen a few things on controlling physics based characters, but I haven't really come across any solutions that I like.
Does anyone have any suggestions / examples of ways to make physics driven characters for a platformer?

I just need a good means of handling running and jumping really.
Also some more advanced features would be nice:
Allowing the character to rotate to match the slope of something but not fall over when it became too steep.
Detect the edges of platforms for extra animation and to allow grabbing on.
Anything else that people can think of.

Re: character movement physics

Posted: Sun Nov 22, 2009 10:42 am
by Robin
This list of things becomes less and less basic as it goes on. :P

For the first few things, a simple custom made collision-detection etc. as I have in Jump Game for example would be enough, but even LovelyBigPlanet doesn't have some of the more advanced things on your list, and that is pretty cool. ;)

To sum it all up: I have no clue how to do this, and wish you good luck.

Re: character movement physics

Posted: Sun Nov 22, 2009 5:36 pm
by Jasoco
Platforming physics is something that has been evolving since 1984 when SMB came out. If you look at SMB from a programmer's perspective you notice how buggy and glitchy the engine really was. But over time the SMB games got better and less buggy. Other side-scrollers came along, and the genre became so advanced.

Look at the newest Mario game that just came out. New Super Mario Bros Wii. It has a lot of stuff that has been perfected in the last 25 years plus new features that Mario only recently started using.

I too want to make a side-scrolling engine. There's a lot of work involved though.

You need to check for collisions with the ground, the ceiling, walls. If you have wall jumps you need to check for a wall to the left or right then allow for using jump again. For edge grabbing you have to check for a corner at a specific place. Climbing ladders is checking for a certain tile behind the player. It's all fun but a lot of work. The player character will have to check for ground. If there is no ground directly below, you need to drop the player a few pixels then check again. When walking, you have to check for the ground as well as making sure there's no wall to the left or right. Jumping you need to check for walls, as well as ceilings. If there's a ceiling where the player wants to go, you need to cancel the jump and revert to gravity once again checking for ground again.

It's best to start simple then work your way up. Get floor detection working first.

Re: character movement physics

Posted: Mon Nov 23, 2009 10:05 am
by Avalon
Jasoco wrote:Platforming physics is something that has been evolving since 1984 when SMB came out. If you look at SMB from a programmer's perspective you notice how buggy and glitchy the engine really was. But over time the SMB games got better and less buggy. Other side-scrollers came along, and the genre became so advanced.

Look at the newest Mario game that just came out. New Super Mario Bros Wii. It has a lot of stuff that has been perfected in the last 25 years plus new features that Mario only recently started using.

I too want to make a side-scrolling engine. There's a lot of work involved though.

You need to check for collisions with the ground, the ceiling, walls. If you have wall jumps you need to check for a wall to the left or right then allow for using jump again. For edge grabbing you have to check for a corner at a specific place. Climbing ladders is checking for a certain tile behind the player. It's all fun but a lot of work. The player character will have to check for ground. If there is no ground directly below, you need to drop the player a few pixels then check again. When walking, you have to check for the ground as well as making sure there's no wall to the left or right. Jumping you need to check for walls, as well as ceilings. If there's a ceiling where the player wants to go, you need to cancel the jump and revert to gravity once again checking for ground again.

It's best to start simple then work your way up. Get floor detection working first.
Correction, Donkey Kong in 1981 and then Mario Bros (original arcade - released in 1983) started the evolution, Super Mario Bros wasn't released in the US until 1986 (end of 1985 in Japan).

Sorry, was just bugging me. :P

Re: character movement physics

Posted: Tue Nov 24, 2009 4:00 pm
by tunzi
One simple way is to define the player as a rectangle. Then you can do collisions based on the top, bottom, left, and right coordinates of the rectangle. The math for colliding with horizontal and vertical lines is straightforward, but I can elaborate if you'd like.

For actual movement you can do this:

Code: Select all

function update(dt)

  p.v_x              -- player's X velocity
  dx = p.v_x * dt    -- Change in x position

  if collide_wall(p) do -- If player collides with any walls
    p.v_x = 0
    dx = 0
  end

  p.x = p.x + dx   -- Move player
end
Then you can have keyboard input modify the player's velocity.

Re: character movement physics

Posted: Tue Nov 24, 2009 8:14 pm
by mikembley
Im unsure, But maybe you are asking for a love.physics based solution?

http://love2d.org/forum/viewtopic.php?f ... 15&start=0

Re: character movement physics

Posted: Fri Nov 27, 2009 2:26 am
by The Burrito
Yes, a solution using box2d is what I was going for, I guess I didn't make that clear.
So for starters, what the best way to handle collision detection for jumping?

Re: character movement physics

Posted: Fri Nov 27, 2009 6:49 am
by Robin
The Burrito wrote:So for starters, what the best way to handle collision detection for jumping?
I know only the LovelyBigPlanet way: have a flag canJump, if you press the jump key and canJump is true, set canJump to false and jump. On collision (any collision), set canJump to true.

Re: character movement physics

Posted: Fri Nov 27, 2009 9:15 am
by bmelts
The Burrito wrote:So for starters, what the best way to handle collision detection for jumping?
Alternatively, if you don't have diagonal/curved surfaces in your game, you can just test to see if the body's Y velocity is 0 (or close to it, thanks floating point). If it is, you can jump.

Re: character movement physics

Posted: Fri Nov 27, 2009 1:12 pm
by Robin
anjo wrote:you can just test to see if the body's Y velocity is 0 (or close to it, thanks floating point). If it is, you can jump.
That has a problem: this might cause a loophole, where you can jump infinitely, if you press the jump key every time you are about to fall down. If you have landed (assuming no slopes etc) the Y velocity will be exactly 0 (unless your collision system is broken, but in that case you have a problem anyway). That is why I have used Y velocity == 0 in Jump Game: it works, and the chance the loophole is activated is minimal. I would even say smaller than the chance of winning the lottery, but that is just a guess.