From 8617784084bc11119613d59c10915a794aa96099 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 13 Jul 2024 04:48:03 +0300 Subject: [PATCH] fix blocks placing when crouching --- doc/ru/scripting/ecs.md | 2 -- src/maths/aabb.hpp | 11 +++++++++++ src/objects/Entities.cpp | 2 +- src/objects/rigging.cpp | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/ru/scripting/ecs.md b/doc/ru/scripting/ecs.md index 4da0a2f4..8970304a 100644 --- a/doc/ru/scripting/ecs.md +++ b/doc/ru/scripting/ecs.md @@ -18,7 +18,6 @@ entity:despawn() -- Возращает имя скелета сущности entity:get_skeleton() -> str - -- Заменяет скелет сущности entity:set_skeleton(name: str) @@ -27,7 +26,6 @@ entity:get_uid() -> int -- Возвращает компонент по имени entity:get_component(name: str) -> компонент или nil - -- Проверяет наличие компонента по имени entity:has_component(name: str) -> bool ``` diff --git a/src/maths/aabb.hpp b/src/maths/aabb.hpp index 67a3f05d..1a86338c 100644 --- a/src/maths/aabb.hpp +++ b/src/maths/aabb.hpp @@ -100,6 +100,17 @@ struct AABB { b.z >= aabb.a.z ); } + + inline bool intersect(const AABB& aabb, float margin) { + return ( + a.x <= aabb.b.x+margin && + b.x >= aabb.a.x-margin && + a.y <= aabb.b.y+margin && + b.y >= aabb.a.y-margin && + a.z <= aabb.b.z+margin && + b.z >= aabb.a.z-margin + ); + } }; #endif // MATHS_AABB_HPP_ diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index ae8b5ddc..3077a3d5 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -407,7 +407,7 @@ void Entities::render(Assets* assets, ModelBatch& batch, const Frustum& frustum, bool Entities::hasBlockingInside(AABB aabb) { auto view = registry.view(); for (auto [entity, eid, body] : view.each()) { - if (eid.def.blocking && aabb.intersect(body.hitbox.getAABB())) { + if (eid.def.blocking && aabb.intersect(body.hitbox.getAABB(), -0.05f)) { return true; } } diff --git a/src/objects/rigging.cpp b/src/objects/rigging.cpp index 8b751a16..909120c0 100644 --- a/src/objects/rigging.cpp +++ b/src/objects/rigging.cpp @@ -88,6 +88,7 @@ static std::tuple> read_node( std::string model; root->str("name", name); root->str("model", model); + std::vector> bones; size_t count = 1; if (auto nodesList = root->list("nodes")) {