Page 1 of 2

yet another collision question thread.

Posted: Sun Apr 20, 2014 1:50 am
by tehryanx
I've been trying really hard to get my head around platformer mechanics. I stopped working on my main project today to try building a really basic platformer from scratch just to get a better understanding of the logic.

The problem I'm trying to solve right now is collision detection. I have a binary map that looks like map[y][x] full of 1's for walls and 0's for air. Then I have a testTile(x,y) function that tries to determine what 32x32 pixel tile x,y is in, and then returns true if it's a wall or false if otherwise. I feel like this is the right way to go about it but I can't get it to work. I've attached my .love to this post if anyone has a second to have a look.

Thanks!

Re: yet another collision question thread.

Posted: Sun Apr 20, 2014 2:12 am
by tehryanx
Wait, nevermind. I solved most of my collision problems, but I have a new one. The problem is that if I don't don't land far enough onto a block i'll fall through it.

Re: yet another collision question thread.

Posted: Sun Apr 20, 2014 7:08 am
by TheScriptan
I suggest you to watch a tutorial of Goature platformer! He made a really cool tutorial

Re: yet another collision question thread.

Posted: Sun Apr 20, 2014 2:38 pm
by tehryanx
I just watched it, but he doesn't actually go into any explanation on the collision detection. He just codes the whole thing without really explaining the logic. :(

Re: yet another collision question thread.

Posted: Sun Apr 20, 2014 3:55 pm
by Ranguna259
The problem your are having is one of the known bugs that come up while coding collision, your collision detection is probably well coded the bug is in the collision response, what happens after the code detects the collision, that's where the problem is.

Re: yet another collision question thread.

Posted: Sun Apr 20, 2014 7:59 pm
by tehryanx
So is it insufficient to just kill the velocity on collision? I'm doing it differently now and I still have problems.

I now have 8 separate collision points as in this picture:

Image

The problem is as illustrated on the right. If I hit a platform directly on the corner, i'm allowed to slide onto the platform and I get stuck. Do I just need 4 more collision events for when I hit the corners?

i've attached the new code below.

Re: yet another collision question thread.

Posted: Sun Apr 20, 2014 8:12 pm
by MadByte
what about this :
Image

Re: yet another collision question thread.

Posted: Sun Apr 20, 2014 8:24 pm
by tehryanx
I'm confused as to how that would work. If I only collide with the top left corner, how do I know which velocity to zero? I might be hitting it from below, but I might be hitting it from the left.

Re: yet another collision question thread.

Posted: Mon Apr 21, 2014 1:44 am
by tehryanx
I imagine there must be a standard way to accomplish this. It's a fundamental part of every platformer so I'm sure I'm reinventing the wheel or tripping myself up in some way that other people have before. I also realize that there are libraries like hardon and bump.lua that could probably handle this for me but I really just want to have a proper understanding of how this stuff works. I've refined everything again and it seems to work except for a minor problem. If I jump into a wall, and then slide down the wall while still holding down the key to accelerate in it's direction it will wrap around the bottom corner of the wall and slide along it as in the diagram below:

Image

Any advice would be greatly appreciated.

Re: yet another collision question thread.

Posted: Mon Apr 21, 2014 9:53 pm
by davisdude
It's because for a short while, you set the y-vel to 0 when colliding with the ceiling. When this happens, you stay colliding to the ceiling until you get out from under it.
By the way, not sure if this was intentional or not: in the .love you put ronnyjumpsalot, but the loading screen has Rony Jompsalot