Having trouble with simple platform collisions

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.
Post Reply
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Having trouble with simple platform collisions

Post 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?
Attachments
main.love
(759 Bytes) Downloaded 136 times
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Having trouble with simple platform collisions

Post 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.
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

Re: Having trouble with simple platform collisions

Post 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)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Having trouble with simple platform collisions

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 75 guests