I have a 3D grid of voxels in my game. Entities walk around with simple physics that represents them as an axis aligned bounding box with velocity, mass and acceleration. The way I'm doing collision resolution is fairly simple. Here's some pseudocode:
function ResolveCollisions() // For each voxel that could intersect the bounding box... foreach (Voxel neighbor in VoxelGrid.GetVoxelsIntersecting(this.bounds)) // Check a collision between the voxel and the bounding box if (neighbor.Collides(this.bounds)) ResolveCollision(neighbor, bounds); function ResolveCollision(Voxel neighbor, BoundingBox bounds) // Compute the contact normal and penetration distance between the two // boxes. [Vector3 norm, float dist] = ComputeMinPenetration(neighbor, bounds); // Snap the position so its no longer colliding this.position += norm * dist; // Reflect the velocity over the normal to perform an elastic collision. this.velocity = this.Restitution * Vector3.Reflect(this.velocity, norm);
This works pretty well for instantaneous collisions and bouncing, but fails for sliding contact. If an entity is sliding across a flat plane of voxels, for instance, it will rapidly bounce, and will sometimes end up colliding with the sides of the voxels instead of the top.
How do I get realistic sliding contact between the bounding box and a voxel grid, without bouncing or "toe stubbing?"