3D AABB collision between two AABBs?

So I’ve managed to get somewhere quite functional with AABB collision with the world (out of blocks) and the player/entity (one AABB), but I’m still having minor issues such as climbing walls or getting stuck in corners. I wonder if this is caused by a flawed implementation of AABBs or my collision code. This is what I have for collision so far:

public void move(float xd, float yd, float zd)
	{
		AABB tempAABB;
		onGround = false;
		ArrayList<AABB> possibleColliders = level.getSurroundingAABBs(entityAABB, 2);
		for(AABB toTest : possibleColliders)
		{
			entityAABB.moveTo(x+xd, y+0.01F, z);
			if(toTest.collides(entityAABB))
				xd = 0;
			entityAABB.moveTo(x+xd, y+0.01F, z+zd);
			if(toTest.collides(entityAABB))
				zd = 0;
			tempAABB = entityAABB.growSides(-0.2F);
			tempAABB.moveTo(x+xd, y+yd, z+zd);
			if(toTest.collides(tempAABB))
			{
				if(yd < 0)
				{
					onGround = true;
					y = (toTest.y1);
				}
				else
				{
					//Necessary?
				}
				yd = 0;
			}
			
		}
		this.setPos(x+xd, y+yd, z+zd);
	}

Am I approaching this very incorrectly? The player AABB is 1.8 blocks tall, and 0.8 blocks wide. Every block in the world is 1x1x1. If this is not enough code, I will gladly show what you need, I just want to avoid a giant wall of text if possible

Your collision detection disregards the actual velocity of the player, or in other words: the actual translation of the player from frame t-1 to frame t.
You assume that you’d catch a possible collision by testing an advance of 0.01 units along each side. If the player’s bounding box, however, is just 0.011 units away from a corner/side of a cube, then you won’t find the intersection now. Then, next frame, assuming the player might actually have moved 0.1 units into the wall, you will find the intersection, but don’t do anything about it anymore, since the player is already stuck in the wall.
To completely combat this, you should implement continuous collision detection and response using swept AABB intersections: https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/swept-aabb-collision-detection-and-response-r3084/

2 Likes

oh I see, I’ll check this out, thanks!