1
\$\begingroup\$

I'm making a game like Minecraft. I have a world made of blocks and I'm trying to implement a basic physic system that applies gravity and checks entities colliding with the blocks of the world.

I tried using Bresenham's algorithm, on player move, to get all blocks between, and then get the first solid and set the player on colliding position. That works well if the player is a point, but if it's a complex AABB and the block too, it becomes difficult.

Is there a simple way to make physic in a voxel world like Minecraft?

\$\endgroup\$
1
  • \$\begingroup\$ You should generally try to avoid doing stuff the same way as Minecraft does, because it's not very optimized most of the time. \$\endgroup\$
    – Bálint
    Commented Mar 24, 2017 at 9:24

1 Answer 1

1
\$\begingroup\$

Minecraft used dynamic- or swept-AABB.

The algorithm works by getting the distance between the AABBs on each axis separately, then using the velocity of the dynamic one to calculate the time it takes to reach the block, and then you pick the axis that collides first. You check if it collides in this frame (aka. time is less than 1), and if it is, you set it's new position to be at the point of collision.

Doing this for millions of blocks is of course very slow, so you should first do a broad phase with the same algorithm by taking the bounding boxes of the chunks instead of separate blocks, and only trying to check for collision against the blocks in the chunk, if the first detection returned true.

I'm not sure if minecraft does the latter.

More on swept AABB:

https://www.gamedev.net/resources/_/technical/game-programming/swept-aabb-collision-detection-and-response-r3084

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I believe Minecraft uses a broadphase that assumes all blocks are full cubes on a regular grid. It then does the narrowphase checks for the blocks returned by the broadphase and the blocks below them, to account for fences being taller than a single block space. \$\endgroup\$ Commented Mar 24, 2017 at 10:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .