voxel - AABB vs AABB collision detection and response -
in c++ implemented small collision detection , response system in small voxel game. aabb vs voxel (the voxel cube it's aabb, too).
actually works fine 1 special exception, if player (aabb) moving in 45 degrees edge of voxel player glitching little in , out fastly. on images down can see it.
now wondering causing problem can't find logical error!? here how in pseudo code currently:
float xnew = xcurrent + xvelocity * deltatime; float ynew = ycurrent + yvelocity * deltatime; float znew = zcurrent + zvelocity * deltatime; float xcorrected = xnew; float ycorrected = ynew; float zcorrected = znew; // if player moving right side. if (xnew < xcurrent) { %do following each of 4 corners of player aabb,% %on right face, until 1 collision occurs% { float x = xnew; float y = ycurrent + %corner_y_offset%; float z = zcurrent + %corner_z_offset%; if (getvoxelat(x, y, z).issolid()) { xcorrected = (unsigned int)x + 1; // abbort , check z axis. break; } } } else if(...) // check opposite direction... // if player moving front side. if (znew < zcurrent) { %do following each of 4 corners of player aabb,% %on right face, until 1 collision occurs% { float x = xcurrent + %corner_x_offset%; float y = ycurrent + %corner_y_offset%; float z = znew; if (getvoxelat(x, y, z).issolid()) { zcorrected = (unsigned int)z + 1; // abbort , check y axis. break; } } } else if(...) // check opposite direction... // y axis check, not important now.... // apply corrected positions. xcurrent = xcorrected; ycurrent = ycorrected; zcurrent = zcorrected;
edit:
z axis, not y axis on screenshot. mistake.
screenshot example http://fs1.directupload.net/images/150722/ottekmg7.png diagram of example http://fs1.directupload.net/images/150722/sldarmk4.png
Comments
Post a Comment