Page 1 of 1

Alright, I got a collision thingy..

Posted: Tue Mar 20, 2012 1:32 pm
by baconhawka7x
So I implemented some crappy-butt collsion into my game, it's super glitchy. So I was wondering if anyone could give me some tips on this?
I shall post a .love(My code is pretty messy though I'm sorry) It's under a function called "apply_gravity" inside of phy-troll.lua


~thanks in advanced

Re: Alright, I got a collision thingy..

Posted: Tue Mar 20, 2012 2:34 pm
by molul
Hey, it's very nice actually. I love how the player still moves a bit when you're not pressing left or right. I also like WASD keys, but not many people here will agree (lol).

I have two suggestions:

-Collision with ceiling is not accurate. It's detected when the player's sprite didn't really touch the ceiling. I'd make the detection start a couple of pixels below (or just reduce the bounding box).

-It's just a personal opinion, but I don't like that the player jumps while keeping the jumping key pressed. I added a variable "player.canJumpAgain = not keypressed([JUMPKEY])" (pseudo-codish) in player.update(), and in the jump chunk I added "if (player.canJumpAgain) then...".

I'll test it deeply at home and get back to you ;)

Re: Alright, I got a collision thingy..

Posted: Thu Mar 22, 2012 3:55 am
by The Burrito
It works pretty well but I did have weird things happen a couple of times, as molul suggested the upper bound and jumping should be fixed.

I'm a little confused by the actual method of collision detection, is "solid" a table of all solid blocks? because I'm pretty sure there are much more efficient ways to collision check.

Looks like your map is already a 2D array, you can check just the nearby tiles pretty easily. I check the tile at math.ceil(x / grid size), math.ceil(y / grid size) where x,y is a location near the player I want to check. This way you're checking for collision of the player with blocks instead of essentially checking every block for the player. This assumes tile 1,1 is top left corner, adjust as needed.

The occasional spazzing I've seen looks like you just need to add a couple of "and something or others" to your code that physically prevents the player from going through solid blocks. Basically so that it considers all points before doing anything. Sorry, don't really have the time to dig in and tell you exactly what to do.