Skip to content

Commit

Permalink
fix colision check on block place
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergwest585 committed Nov 4, 2024
1 parent 513b96e commit 726ee8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/logic/PlayerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,15 @@ void PlayerController::processRightClick(const Block& def, const Block& target)
}
blockid_t chosenBlock = def.rt.id;

AABB blockAABB(coord, coord + 1);
bool blocked = level->entities->hasBlockingInside(blockAABB);

if (def.obstacle && blocked) {
return;
if (def.obstacle) {
std::vector<AABB> hitboxes = def.rotatable ? def.rt.hitboxes[state.rotation] : def.hitboxes;
for (AABB blockAABB : hitboxes) {
bool blocked = level->entities->hasBlockingInside(blockAABB.move(coord));
if (blocked) {
return;
}
}
}
auto vox = chunks->get(coord);
if (vox == nullptr) {
Expand Down
4 changes: 4 additions & 0 deletions src/maths/aabb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct AABB {
return (a + b) * 0.5f;
}

inline AABB move(glm::vec3 pos) const {
return AABB(a + pos, b + pos);
}

/// @brief Multiply AABB size from center
inline void scale(const glm::vec3 mul) {
glm::vec3 center = (a + b) * 0.5f;
Expand Down

0 comments on commit 726ee8a

Please sign in to comment.