Working Out Collision Detection
by Cory on September 15, 2018 12:46 PM
I've implemented the "regular" AABB collision detection, which is basically just seeing if two squares overlap. According to the internet, this algorithm isn't good when things start moving because you can get a tunneling effect.
I also spent a couple of weeks trying to implement "swept AABB" and had an embarrassingly hard time. I don't really have an easy way to debug this stuff right now, so I spent some time printing out physics variables to the screen and drawing vectors in different colors to the screen.
I managed to get it mostly working, but there's still a lot of wrinkles to smooth out. For instance, you can see in the gif that it detects collisions on the y axis sometimes when it shouldn't. I get stuck under the plantform even though I'm way to the right of it.
Also because of how the collision detection works, when I'm going left or right on the platform, the collision detection alternates between colliding and not colliding every frame. What happens here is that one the frames when it's not colliding (going exactly sideways), the physics system applies gravity. On the next frame, the downward velocity causes the system to register a collision and stop applying gravity acceleration. The problem with this is right now is that I test to see if the vertical velocity is 0 to see if the player can jump, so a lot of times when I press the button it doesn't work.
This Thought is part of Game Programming
Game programming general topic. I eventually hope to split this into separate ideas exclusively about specific games that I make.