I'm currently working on a block world engine in XNA and can't get the collision detection and handling to work properly. The world is in an array indexed with ( z * width * width + y * width + x ) and containing different blocks represented by bytes. All fine and dandy. Or so I thought.
I've tried different techniques for collision handling and I'm currently using a version where I calculate the players/cameras direction and before adding it to the position I check each individual vector (x, y and z) with half a units offset (to compensate for the block size of 1.0) against the world and only apply it when the result is zero. So far so good. Now the problem arise when I walk straight into a corner because the x- and z-axis does not intersect/collide until after I've come a bit into the cube.
So how am I to properly calculate collision detection and handling in a block world?
I would really like some input on this matter, and preferably on a higher/conceptual level, but code examples are of course welcome aswell.
To further explain my situation, based upon @A-Type's response:
So, let's be more precise here to help me understand you. My character is only one unit big in every direction, which should make things easier.
First of all, do you reccon I should update my characters position first and check for collissions after? This would be my prefered way of doing collision detection but if it's any easier I'll check first and move later if possible.
Well, I understand that the player can only be intersecting 8 cubes (in your example 12) and the rounding seems to be a very good idea too, but I don't quite see the transition from the 12 cubes (again in your example, mine would be 8) to only 3. Wont this cause the same problem where the corners of the character-cube wont be taken into consideration?
I have tried to implement this but failed, so I thought more theory might do it. (I've actually gotten the collision detection to work but in those cases I lost my speed completely, not just in the colliding direction.)
Thanks for your time!
Karl