yet another collision question thread.

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.
tehryanx
Prole
Posts: 17
Joined: Fri Apr 04, 2014 8:26 pm

yet another collision question thread.

Post 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!
Last edited by tehryanx on Sun Apr 20, 2014 2:13 am, edited 1 time in total.
tehryanx
Prole
Posts: 17
Joined: Fri Apr 04, 2014 8:26 pm

Re: yet another collision question thread.

Post 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.
Attachments
ronnyjompsalot.love
(1.78 KiB) Downloaded 124 times
TheScriptan
Citizen
Posts: 56
Joined: Wed Feb 27, 2013 7:53 pm

Re: yet another collision question thread.

Post by TheScriptan »

I suggest you to watch a tutorial of Goature platformer! He made a really cool tutorial
tehryanx
Prole
Posts: 17
Joined: Fri Apr 04, 2014 8:26 pm

Re: yet another collision question thread.

Post 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. :(
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: yet another collision question thread.

Post 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.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
tehryanx
Prole
Posts: 17
Joined: Fri Apr 04, 2014 8:26 pm

Re: yet another collision question thread.

Post 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.
Attachments
ronnyjumpsalot.love
(1.97 KiB) Downloaded 133 times
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: yet another collision question thread.

Post by MadByte »

what about this :
Image
tehryanx
Prole
Posts: 17
Joined: Fri Apr 04, 2014 8:26 pm

Re: yet another collision question thread.

Post 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.
tehryanx
Prole
Posts: 17
Joined: Fri Apr 04, 2014 8:26 pm

Re: yet another collision question thread.

Post 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.
Attachments
ronnyjumpsalot.love
(2.53 KiB) Downloaded 115 times
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: yet another collision question thread.

Post 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
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Post Reply

Who is online

Users browsing this forum: No registered users and 80 guests