Optimized collision detection in minecraft-like game?

Started by
1 comment, last by Nypyren 5 years, 11 months ago

Hi, I'm currently implementing a minecraft-like game in Opengl.

I'm trying to resolve the collision issue.

first option- Putting the colliders to all blocks(bad idea for performance)

second option- Save block information around the player and check collisions. (10 blocks around the player since the size of player is 2 cubes)

Is there a more optimized way to check the collision than the second option?

Thank you!

 

 

 

Advertisement

Get the grid-aligned bounding box of your dynamic object (your player in this case).  Convert its min and max coordinates to grid cell coordinates.  That range of cells are the only ones you need to test for collisions.  If you have block shapes other than just cubes, you can use 'shape templates' (id(s) stored per block - or associated with the block type - which represent what shape it is).

You don't need to save the blocks around the player in a second data structure since you can access them from the block grid in constant time.

This topic is closed to new replies.

Advertisement