temporary fixed grass hitbox

This commit is contained in:
MihailRis
2023-11-29 13:29:28 +03:00
parent f3889421d8
commit cad1f6a669
3 changed files with 38 additions and 17 deletions
+34 -9
View File
@@ -200,20 +200,45 @@ voxel* Chunks::rayCast(vec3 start,
while (t <= maxDist){
voxel* voxel = get(ix, iy, iz);
if (voxel == nullptr || contentIds->getBlockDef(voxel->id)->selectable){
const Block* def = nullptr;
if (voxel == nullptr || (def = contentIds->getBlockDef(voxel->id))->selectable){
end.x = px + t * dx;
end.y = py + t * dy;
end.z = pz + t * dz;
// TODO: replace this dumb solution with something better
if (def && def->hitboxScale < 1.0f) {
const float sz = def->hitboxScale;
const int subs = 16;
for (int i = 0; i < subs; i++) {
end.x += dx / float(subs);
end.y += dy / float(subs);
end.z += dz / float(subs);
if (end.x - ix >= 0.5f - sz * 0.5f && end.x - ix <= 0.5f + sz * 0.5f &&
end.y - iy >= 0.0f && end.y - iy <= sz &&
end.z - iz >= 0.5f - sz * 0.5f && end.z - iz <= 0.5f + sz * 0.5f) {
iend.x = ix;
iend.y = iy;
iend.z = iz;
iend.x = ix;
iend.y = iy;
iend.z = iz;
norm.x = norm.y = norm.z = 0.0f;
if (steppedIndex == 0) norm.x = -stepx;
if (steppedIndex == 1) norm.y = -stepy;
if (steppedIndex == 2) norm.z = -stepz;
return voxel;
}
}
} else {
iend.x = ix;
iend.y = iy;
iend.z = iz;
norm.x = norm.y = norm.z = 0.0f;
if (steppedIndex == 0) norm.x = -stepx;
if (steppedIndex == 1) norm.y = -stepy;
if (steppedIndex == 2) norm.z = -stepz;
return voxel;
norm.x = norm.y = norm.z = 0.0f;
if (steppedIndex == 0) norm.x = -stepx;
if (steppedIndex == 1) norm.y = -stepy;
if (steppedIndex == 2) norm.z = -stepz;
return voxel;
}
}
if (txMax < tyMax) {
if (txMax < tzMax) {