add entities raycast

This commit is contained in:
MihailRis
2024-07-14 10:50:06 +03:00
parent 638a0d9850
commit c17f3fec54
8 changed files with 90 additions and 15 deletions
+15 -4
View File
@@ -264,8 +264,7 @@ void PlayerController::postUpdate(float delta, bool input, bool pause) {
if (input) {
updateInteraction();
} else {
player->selection.vox.id = BLOCK_VOID;
player->selection.vox.state.rotation = 0;
player->selection = {};
}
}
@@ -365,13 +364,25 @@ voxel* PlayerController::updateSelection(float maxDistance) {
maxDistance,
end, norm, iend
);
if (vox == nullptr) {
if (vox) {
maxDistance = glm::distance(camera->position, end);
}
selection.entity = ENTITY_NONE;
selection.actualPosition = iend;
if (auto result = level->entities->rayCast(
camera->position, camera->front, maxDistance, player->getEntity())) {
selection.entity = result->entity;
selection.hitPosition = camera->position + camera->front * result->distance;
selection.position = selection.hitPosition;
selection.actualPosition = selection.position;
selection.normal = result->normal;
}
if (vox == nullptr || selection.entity) {
selection.vox = {BLOCK_VOID, {}};
return nullptr;
}
blockstate selectedState = vox->state;
selection.vox = *vox;
selection.actualPosition = iend;
if (selectedState.segment) {
selection.position = chunks->seekOrigin(
iend, indices->blocks.get(selection.vox.id), selectedState