mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add entity events: on_aim_on, on_aim_off
This commit is contained in:
parent
54902d7f49
commit
a36ffaacd9
3 changed files with 31 additions and 0 deletions
|
|
@ -357,6 +357,7 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
|||
if (vox) {
|
||||
maxDistance = glm::distance(camera->position, end);
|
||||
}
|
||||
auto prevEntity = selection.entity;
|
||||
selection.entity = ENTITY_NONE;
|
||||
selection.actualPosition = iend;
|
||||
if (auto result = level->entities->rayCast(
|
||||
|
|
@ -367,6 +368,18 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
|||
selection.actualPosition = selection.position;
|
||||
selection.normal = result->normal;
|
||||
}
|
||||
if (selection.entity != prevEntity) {
|
||||
if (prevEntity != ENTITY_NONE) {
|
||||
if (auto pentity = level->entities->get(prevEntity)) {
|
||||
scripting::on_aim_off(*pentity, player.get());
|
||||
}
|
||||
}
|
||||
if (selection.entity != ENTITY_NONE) {
|
||||
if (auto pentity = level->entities->get(selection.entity)) {
|
||||
scripting::on_aim_on(*pentity, player.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vox == nullptr || selection.entity) {
|
||||
selection.vox = {BLOCK_VOID, {}};
|
||||
return nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue