Questions about platformer game

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.
gregkwaste
Prole
Posts: 19
Joined: Fri Aug 31, 2012 8:32 am

Questions about platformer game

Post by gregkwaste »

Hi there guys,

I've been reading these forums for months now but since starting developing a love game, i am starting to feel like i need a little help. So what would i find a better place for my questions ^^.


So i am making a platform game, mario-style, with maps created with tiled software.

after programming the basic moves, i started messing around with collisions with the map in order to make my player interact with the platforms. I successfully did that with 2 ways:

1. Only with advanced loader, i check the player coordinates(the y coordinate) if they "collide" with the tiles with the ground property, and if the conditions match then make my players vertical speed zero.

2. With hardoncollider, i read all the map, and draw rectangles on every groundtile in the map then call the collision callback whenever my player's rectangle collides with the tile rectangles.



Both ways are problematic... Sometimes randomly when jumping my player just passes inside the tiles without colliding... Some other times i see that the collision is accompished but the player's change of vertical speed is not fast enough resulting the player to pass the tile, and then keep falling down (because there are no more collisions....)

With the second way, i am experiencing a huge lag when walking on the collision boxes...(it uses almost 700 mbs of ram.....) And thats why again when my player jumps with so much lagging there are times that the collision callback function is never been called...

With both ways the serious problems are while jumping... And another issue that just gets on my nerves is that my player's landing on the tile is never constant... Because of the collision lagging in both ways, my players y coordinate after jumping is never the same, it may be lower it may be higher, if the game lags instantly, my player will land in the middle of the tile. if it doesn't he will land at the top of it...

Am i heading the wrong way? Which one is the correct one, and what do i need to change? There is always the solution to directly affect the players y coordinate on the collision, but it must be a better way to do it...

any help is highly appreciated
thanks in advance
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Questions about platformer game

Post by coffee »

Some fast advices about platform techniques.
First of you should limit your dt for avoid "tunneling" problems with math.min(dt, 0.06) or other reasonable number. This is a problem found that can happen usually at start if player or other objects airborn/falling and make your character end inside wall/floor without your detection system have a chance to avoid it. Also avoid dt fluctuations.

There are several ways techniques to resolve to don't let your player (and other stuff) enter in walls.
1 - Avoid to move to a place where is "solid". However this can usually create problems of gaps between the movable object and the wall and whatever your dt is never enough/accurate to snap perfectly with wall.
2 - Let player move, check if in conflit and then correct position by snapping to the nearest grid position. Usually the best thing to do.

Check those with related problems like yours
viewtopic.php?f=4&t=10070&p=61375
viewtopic.php?f=4&t=8023 (hardon library related but principles applies.
viewtopic.php?f=4&t=9391&p=58132
Last edited by coffee on Fri Aug 31, 2012 10:23 am, edited 1 time in total.
gregkwaste
Prole
Posts: 19
Joined: Fri Aug 31, 2012 8:32 am

Re: Questions about platformer game

Post by gregkwaste »

coffee wrote:Some fast advices about platform techniques.
First of you should limit your dt for avoid "tunneling" problems with math.min(dt, 0.06) or other reasonable number. This is a problem found that can happen usually at start and can make your character end inside wall/floor without your detection system can avoid it.

There are several ways techniques to resolve to don't let your player (and other stuff) enter in walls.
1 - Avoid to move to a place where is "solid". However this can usually create problems of gaps between the movable object and the wall and whatever your dt is never enough/accurate to snap perfectly with wall.
2 - Let player move, check if in conflit and then correct position by snapping to the nearest grid position. Usually the best thing to do.

hmmmm i didn't get the first one to be honest, math.min will actually reduce dt?? or make it a fix value somehow?


i'll highly consider the 2nd option, and i'll try to figure out how to do it.

thanks :)
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Questions about platformer game

Post by coffee »

gregkwaste wrote: hmmmm i didn't get the first one to be honest, math.min will actually reduce dt?? or make it a fix value somehow?
math.min(dt, value) will avoid that if your dt is for some reason too high will be clamped to a safe value that will not let your things get huge displacements from the place originally where. The value 0.06 is calculated based in fps.
Sorry I only added after reply useful links that you probably didn't catch. I Didn't went more in detail and technical because I was expecting you to read the indicated threads. Technical discussion about it is there.

Also check this one
viewtopic.php?f=4&t=8740
gregkwaste
Prole
Posts: 19
Joined: Fri Aug 31, 2012 8:32 am

Re: Questions about platformer game

Post by gregkwaste »

coffee wrote:
gregkwaste wrote: hmmmm i didn't get the first one to be honest, math.min will actually reduce dt?? or make it a fix value somehow?
math.min(dt, value) will avoid that if your dt is for some reason too high will be clamped to a safe value that will not let your things get huge displacements from the place originally where. The value 0.06 is calculated based in fps.
Sorry I only added after reply useful links that you probably didn't catch. I Didn't went more in detail and technical because I was expecting you to read the indicated threads. Technical discussion about it is there.

Also check this one
viewtopic.php?f=4&t=8740

wow i did't see the edited post ^^

Now i get what happens with that, i tried it just now, but the problem with HC still exists... tha lagging is there, the tunneling is there...

i'll read the topics you added and find out more information

thanks :)
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Re: Questions about platformer game

Post by dreadkillz »

If you're feeling adventurous, you can take a look at the code for Mari0. That's as good as a platformer example as you can get.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Questions about platformer game

Post by coffee »

dreadkillz wrote:If you're feeling adventurous, you can take a look at the code for Mari0. That's as good as a platformer example as you can get.
Even that Mari0 is an awesome platformer would be preferable if he check less complex code examples. He only need to know the principles. Not always the best is the suitable example for learn. For example Puzzlemoon posted yesterday about his well done plataformer. His code should be simpler but efficient enough concerning colisions. Things don't get stuck, no margins between walls. Also the game is a blast of fun.
http://www.ludumdare.com/compo/ludum-da ... &uid=11003
gregkwaste
Prole
Posts: 19
Joined: Fri Aug 31, 2012 8:32 am

Re: Questions about platformer game

Post by gregkwaste »

i followed'd coffee's instruction to make the coordinates snap on collision..
After some coding and tweaking everything works like a charm ^^. So for now that is the way that i am going to use :)

i downloaded the source of puzzlemoon, but i don't think its going to help me, my collision checking has a lot to do with advanced tiled editor, so i don't think that i'll find any similarities in it.

Another question that i am having is , how the heck can i add moving platforms.... The simplest way i can think is to predraw the platform in a specific object layer, and somehow add a drawing function, but for now the only thing i can do is to study kadoba's wiki...
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Questions about platformer game

Post by coffee »

I'm glad you doing progress.
gregkwaste wrote: Another question that i am having is , how the heck can i add moving platforms.... The simplest way i can think is to predraw the platform in a specific object layer, and somehow add a drawing function, but for now the only thing i can do is to study kadoba's wiki...
Perhaps this can help:
Moving platforms can seem a little tricky, but are actually fairly simple. Unlike normal platforms, they cannot be represented by fixed tiles (for obvious reasons), and instead should be represented by an AABB, that is, a rectangle that cannot be rotated. It is a normal obstacle for all collision purposes, and if you stop here, you’ll have very slippery moving platforms (that is, they work as intended, except that the character does not move along it on his own).

There are a few different ways to implement that. One algorithm is as follows:
Before anything on the scene is stepped, determine whether the character is standing on a moving platform. This can be done by checking, for example, whether his center-bottom pixel is just one pixel above the surface of the platform. If it is, store a handle to the platform and its current position inside the character.
Step all moving platforms. Make sure that this happens before you step characters.
For every character that’s standing on a moving platform, figure the delta-position of the platform, that is, how much it has moved along each axis. Now, shift the character by the same amount.
Step the characters as usual.
That is taken from this tutorial. Is quite good and could help you with other problems.
http://www.gamedev.net/page/resources/_ ... mers-r2936
gregkwaste
Prole
Posts: 19
Joined: Fri Aug 31, 2012 8:32 am

Re: Questions about platformer game

Post by gregkwaste »

before reading the tutorial you posted, i have to say that i managed to do it ^^.


Man this feeling when you see the platform moving is just undescribable xD
Post Reply

Who is online

Users browsing this forum: No registered users and 167 guests