add entities raycast
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user