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

View File

@ -71,7 +71,7 @@ void setup_definitions(ContentBuilder* builder) {
block->lightPassing = true;
block->obstacle = false;
block->model = BlockModel::xsprite;
block->hitboxScale = 0.5f;
block->hitboxScale = 0.7f;
builder->add(block);
block = new Block("base:flower", "flower");

View File

@ -168,13 +168,9 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera, bool occlusion)
linesShader->use();
linesShader->uniformMatrix("u_projview", camera->getProjView());
lineBatch->lineWidth(2.0f);
if (block->model == BlockModel::block){
lineBatch->box(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f,
1.008f,1.008f,1.008f, 0,0,0,0.5f);
} else if (block->model == BlockModel::xsprite){
lineBatch->box(pos.x+0.5f, pos.y+0.35f, pos.z+0.5f,
0.805f,0.705f,0.805f, 0,0,0,0.5f);
}
float size = block->hitboxScale;
lineBatch->box(pos.x+0.5f, pos.y+size*0.5f, pos.z+0.5f,
size, size, size, 0, 0, 0, 0.5f);
lineBatch->render();
}
skybox->unbind();

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) {