Alright, I got a collision thingy..

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
baconhawka7x
Party member
Posts: 494
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Alright, I got a collision thingy..

Post 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
Attachments
Archive.love
asdfa;sdlkfjas;dlkfjals;dfjqwpeoiruqpwoeijaf;sldkjf;LKDJAS;LDKFJA;SLDKFJADKLS;F
(71.2 KiB) Downloaded 175 times
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Alright, I got a collision thingy..

Post 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 ;)
User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

Re: Alright, I got a collision thingy..

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

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests