From e98996e6a97f86a82ebb71cbd1da838b144639d4 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 24 Feb 2026 23:55:00 +0300 Subject: [PATCH] feat: ceiling collision for solid entities --- src/physics/PhysicsSolver.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index 58c48ce1e..400952567 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -274,7 +274,7 @@ void PhysicsSolver::calcCollisions( if (vel.y > 0.0f){ AABB boxAABB = AABB(-half, +half); - boxAABB.scale(glm::vec3(1.0f - E * 2, 1.0f + E * 2, 1.0f - E * 2)); + boxAABB.scale(glm::vec3(1.0f - E * 4, 1.0f + E * 2, 1.0f - E * 4)); boxAABB = boxAABB.translated(pos); for (int ix = 0; ix <= glm::ceil((half.x-E)*2); ix++) { @@ -293,6 +293,22 @@ void PhysicsSolver::calcCollisions( } } } + for (auto box : solidHitboxes) { + if (glm::distance2(box->position, pos) < E) { + continue; + } + auto boxhalf = box->getHalfSize(); + if (box->getAABB().intersects(boxAABB)) { + float newy = box->position.y - boxhalf.y - half.y; + if (pos.y > newy) { + pos.y = newy; + } + if (vel.y > 0.0f) { + vel.y = 0.0f; + break; + } + } + } } for (int axis = 0; axis < 3; axis++) {