0

How do games like 3D Games Minecraft with a grid handle collisions their are thousands of block divided into chunks each with its own bounding box

how is collision detected calculated and processed

i tried AABB but it didnt work well with each block having its own collider

is their a way to check collision with a WHOLE MESH

this is the crude AABB function i could come up with

bool Entity::AABB(int x, int y, int z) {
return
    (x - 1 <= Position.x && x >= Position.x - Size.x) &&
    (y - 1 <= Position.y && y >= Position.y - Size.y) &&
    (z - 1 <= Position.z && z >= Position.z - Size.z);
}

plz help... Thanks

  • No, I think you would have to go through every face/block. But, I think Minecraft does not actually compute unnecessary computations, only computing the blocks that could be interacted with. So, do the least amount of work as possible. – cs1349459 Sep 30 '22 at 15:10
  • You can do mesh collision checks by checking every single triangle/face of a mesh for collision but that is extremely slow, that's why usually you first use things like AABB or spheres for rough checks. But what you seem to be looking for are spatial data structures that reduce the amount of objects you need to check against – UnholySheep Sep 30 '22 at 15:12
  • MC divides it's world into 16x16x16 groups of blocks called chunks. A player can only collided with blocks in the 27 chunks (3x3x3 cube) around the players position. MC also keeps track of all visible (render distance) exposed surfaces and a player can only collide with an exposed surface. Combining these two factors drastically reduces the number of collision checks. Further optimisation are also possible if you know how far an entity moved in the last game tick as only block with this range need to be checked. – Richard Critten Sep 30 '22 at 15:23

1 Answers1

2

Minecraft first calculates the player's AABB, then rounds it bigger to a whole number of blocks on each side, then checks whether the player's AABB (not rounded) collides with the AABB of any of the blocks in the rounded AABB.

One extra block is added on the bottom, because fence blocks have AABBs that go up into the next block space above themselves. If the collision check didn't check one block below the AABB, it would miss out on fences.

Chunks are irrelevant for this.

user253751
  • 57,427
  • 7
  • 48
  • 90