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
Alright, I got a collision thingy..
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- baconhawka7x
- Party member
- Posts: 494
- Joined: Mon Nov 21, 2011 7:05 am
- Location: Oregon, USA
- Contact:
Alright, I got a collision thingy..
- Attachments
-
- Archive.love
- asdfa;sdlkfjas;dlkfjals;dfjqwpeoiruqpwoeijaf;sldkjf;LKDJAS;LDKFJA;SLDKFJADKLS;F
- (71.2 KiB) Downloaded 174 times
Re: Alright, I got a collision thingy..
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
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
- The Burrito
- Party member
- Posts: 153
- Joined: Mon Sep 21, 2009 12:14 am
- Contact:
Re: Alright, I got a collision thingy..
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.
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.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 6 guests