1
\$\begingroup\$

I'm making a voxel game with cubes - like in minecraft - and I have figured out how to check wether the player is colliding with a voxel, I have just done it by checking wether the player is within a voxel which is not air, however I don't know how to respond to that i know that the player is inside of a solid cube/voxel. Can anyone please suggest how to do it?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

Voxels can be considered Axis Aligned Bounding Boxes (AABB)s. I suggest looking up the math surrounding collision detection and AABBs. It's actually quite simple as you can describe an AABB with just two Vectors (a maximum and minimum point).

Here's a super simple example: http://www.miguelcasillas.com/?p=30

Of course AABB collision detection is really easy if you're just colliding with points, AABBs and Spheres. If you want to handle collision detection with complex shapes you'll need to explore Oriented Bounding Boxes (OBB)s and the Separating Axis Theorem.

\$\endgroup\$
2
  • \$\begingroup\$ How can i make a response to the collision? \$\endgroup\$
    – Torrek
    Jul 27, 2015 at 19:48
  • \$\begingroup\$ That's a whole other question. Collision response is a hefty topic. This is my favourite paper by Chris Hecker: chrishecker.com/images/e/e7/Gdmphys3.pdf \$\endgroup\$
    – Honeybunch
    Jul 27, 2015 at 19:53
1
\$\begingroup\$

The answer to "How to handle collision" part of your question is something like this:

First you need to quickly discard pairs of voxels that are too far away to be colliding (think spatial partition).

Then for each pair of voxels that are candidate to collision you should:

  • check if they really are colliding;
  • generate the collision data {penetration, collision_normal} (for voxels it's pretty easy, check which axis has the bigger penetration and output this as the penetration and the axis as the collision normal, just make sure to define a rule for the normal, for instance, it always point to the first voxel of the pair);
  • then you resolve the penetrations (move the voxels away from each other by penetration amount in each axis);
  • and finally you have to add a force OR an impulse (both methods have their pros and cons, I particularly prefer impulse than force) to the center of each non static voxel using the normal as base for impulse direction and penetration as base for impulse magnitude. And you don't have to worry about angular impulse and angular momentum since voxels don't spin.

Hope it helps.

\$\endgroup\$

You must log in to answer this question.

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