Page 1 of 1

Having trouble with simple platform collisions

Posted: Mon Apr 25, 2016 5:37 am
by Vimm
in this platform example i made cuz i was bored, i got most things working except for collisions. I can jump from one platform to another just fine, but if i collide with the side or the bottom a platform, im teleported to the top of it. I know why this happens but I cant think of a proper way to fix it, not without entirely messy and broken code anyway.

any tips?

Re: Having trouble with simple platform collisions

Posted: Tue May 03, 2016 11:45 am
by CaptainMaelstrom
Use a collision library to handle collision detection for you. I recommend bump (kikito) or vrld's hump library. You can find them in the wiki.

This way, you don't have to maintain or worry about most of the collision code, and can focus on how you want to resolve them.

Re: Having trouble with simple platform collisions

Posted: Tue May 10, 2016 10:58 pm
by Chroteus
Hey,
Fİrst of all, there are few bugs.
love.keypressed shouldn't be defined in love.update but rather separately like all other love functions.
Secondly, love.window.getWidth()/getHeight() are removed from newest Love version. use love.graphics.getWidth()/getHeight() instead.
Thirdly, jumping doesn't work. Use "space" as a string for spacebar.

Regarding collision, you've got really basic collision resolving.
You don't check whether it collided from left or right, etc. That means whenever it collides player is sent up.
Collision detection can be quite a challenge in some cases, so I won't link you a long ass article.
Instead I'd recommend you to check where player is colliding from and resolve based on that.

(Also, regarding using libraries; don't. You're still a beginner, and using libraries won't help you at this point, trust me)

Re: Having trouble with simple platform collisions

Posted: Wed May 11, 2016 6:29 am
by s-ol
Chroteus wrote: (Also, regarding using libraries; don't. You're still a beginner, and using libraries won't help you at this point, trust me)
I do not agree with this. Yes, sometimes it's better to learn how to do things yourself but collision detection and collision resolution are (or can be) a very complex matter and implementing them yourself, especially as a beginner, is going to lead to much worse results and proably code structure etc... IF OP even manages to do it, chances are it will be very buggy or take so much time he burns out of the project before he even gets to do gameplay.

@CaptainMaelstrom: vrld's hump doesn't do collision detection, you probably meant HardonCollider, but that would probably also not help OP since it's a collision detectioj library and OPs troubles lie in collision resolution. Bump ks very much the way to go IMO.