I just wanted to start off by saying that I’m pretty sure there is something out there on this topic, but I don’t really understand them. Please don’t scream at me to Google it.
So, anyways, ahead with the question. I’ve started working on a Voxel game(just a Minecraft clone to work on programming), and I’ve got some rendering done. This rendering isn’t very complicated, but I want collision done before the other stuff. I’ve gotten AABB’s setup and collision detection down, but I couldn’t get the collision detection working. Also, this collision doesn’t work if the player is travelling extraordinarily fast, so I was also wondering if there was a better method.
I’m using this to determine collision:
if (boundingBox.maxX + boundingBox.x > aabb.minX + aabb.x &&
boundingBox.minX + boundingBox.x < aabb.maxX + aabb.x &&
boundingBox.maxY + boundingBox.y > aabb.minY + aabb.y &&
boundingBox.minY + boundingBox.y < aabb.maxY + aabb.y &&
boundingBox.maxZ + boundingBox.z > aabb.minZ + aabb.z &&
boundingBox.minZ + boundingBox.z < aabb.maxZ + aabb.z) {
return true;
}
boundingBox is the player AABB and aabb is the AABB that we are checking collision for.
I’m adding the maxX to the x position, because the maxX is not absolute.