fix side collision position correction

This commit is contained in:
MihailRis 2026-03-09 16:35:28 +03:00
parent 0fe0cc5829
commit a8dd5e9cb3
2 changed files with 7 additions and 5 deletions

View file

@ -320,7 +320,8 @@ void Entities::updatePhysics(float delta) {
for (int solid = false; solid <= true; solid++) { for (int solid = false; solid <= true; solid++) {
for (auto [entity, eid, transform, rigidbody] : view.each()) { for (auto [entity, eid, transform, rigidbody] : view.each()) {
if (!rigidbody.enabled || rigidbody.hitbox.type == BodyType::STATIC) { if (!rigidbody.enabled ||
rigidbody.hitbox.type == BodyType::STATIC) {
continue; continue;
} }
if (eid.def.solid == solid) { if (eid.def.solid == solid) {

View file

@ -12,7 +12,8 @@
#define GLM_ENABLE_EXPERIMENTAL #define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/norm.hpp> #include <glm/gtx/norm.hpp>
inline const float E = 0.03f; inline constexpr float E = 0.03f;
inline constexpr float MAX_FIX = 0.15f;
static debug::Logger logger("physics-solver"); static debug::Logger logger("physics-solver");
@ -78,7 +79,7 @@ static void calc_collision(
} else { } else {
continue; continue;
} }
if ((pos[nx] - newx) * sign > 0.0f) { if ((pos[nx] - newx) * sign > 0.0f && glm::abs(pos[nx] - newx) < MAX_FIX) {
if (vel[nx] * sign > 0.0f) { if (vel[nx] * sign > 0.0f) {
vel[nx] = 0.0f; vel[nx] = 0.0f;
} }
@ -137,7 +138,7 @@ static bool calc_collision_neg_y(
auto boxhalf = box->getHalfSize(); auto boxhalf = box->getHalfSize();
if (box->position.y < pos.y && box->getAABB().intersects(aabb)) { if (box->position.y < pos.y && box->getAABB().intersects(aabb)) {
float newy = box->position.y + boxhalf.y + half.y; float newy = box->position.y + boxhalf.y + half.y;
if (pos.y < newy && glm::abs(pos.y - newy) < 0.5f) { if (pos.y < newy && glm::abs(pos.y - newy) < boxhalf.y) {
pos.y = newy; pos.y = newy;
} }
if (glm::abs(box->delta) > 1e-5f) { if (glm::abs(box->delta) > 1e-5f) {