I've been writing this collision detection system using a tutorial from an article I read and I just cannot for the life of me get it to function 100% correctly. Here's the code for starters:
BoundingBox aBox; aBox.Convert(a); BoundingBox bBox; bBox.Convert(b); Vector2 aMin = aBox.GetTopLeft(); Vector2 aMax = aBox.GetBotRight(); Vector2 bMin = bBox.GetTopLeft(); Vector2 bMax = bBox.GetBotRight(); Vector2 minDistance; float left = (bMin.x - aMax.x); float right = (bMax.x - aMin.x); float top = (bMin.y - aMax.y); float bottom = (bMax.y - aMin.y); // Check for intersection internally if (left > 0 || right < 0) return; if (top > 0 || bottom < 0) return; // Find the minDistance if (abs(left) < right) minDistance.x = left; else minDistance.x = right; if (abs(top) < bottom) minDistance.y = top; else minDistance.y = bottom; // Null axis with biggest value if (abs(minDistance.x) < abs(minDistance.y)) minDistance.y = 0; else minDistance.x = 0;
The problem right now is that the character is fine walking and hugging the top of a block and the bottom of a block, but once he has to walk UP two blocks, he gets stuck in between them. Coincidentally, walking down works perfectly fine. Just wondering if anyone has a solution to this problem, it would be much appreciated!
Here's a gif to better display the problem: