character movement physics

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

character movement physics

Post by The Burrito » Sun Nov 22, 2009 6:53 am

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.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: character movement physics

Post by Robin » Sun Nov 22, 2009 10:42 am

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.
Help us help you: attach a .love.

User avatar
Jasoco
Inner party member
Posts: 3650
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: character movement physics

Post by Jasoco » Sun Nov 22, 2009 5:36 pm

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.

User avatar
Avalon
Prole
Posts: 49
Joined: Sat Sep 12, 2009 11:37 am

Re: character movement physics

Post by Avalon » Mon Nov 23, 2009 10:05 am

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

User avatar
tunzi
Prole
Posts: 4
Joined: Sat Nov 21, 2009 10:21 pm

Re: character movement physics

Post by tunzi » Tue Nov 24, 2009 4:00 pm

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.

User avatar
mikembley
Citizen
Posts: 72
Joined: Wed Dec 17, 2008 5:30 pm
Location: Blackburn, UK
Contact:

Re: character movement physics

Post by mikembley » Tue Nov 24, 2009 8:14 pm

Im unsure, But maybe you are asking for a love.physics based solution?

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

User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

Re: character movement physics

Post by The Burrito » Fri Nov 27, 2009 2:26 am

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?

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: character movement physics

Post by Robin » Fri Nov 27, 2009 6:49 am

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.
Help us help you: attach a .love.

User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: character movement physics

Post by bmelts » Fri Nov 27, 2009 9:15 am

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.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: character movement physics

Post by Robin » Fri Nov 27, 2009 1:12 pm

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.
Last edited by Robin on Fri Nov 27, 2009 4:16 pm, edited 1 time in total.
Help us help you: attach a .love.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 13 guests