improve it cautiously

This commit is contained in:
MihailRis 2026-03-03 19:58:23 +03:00
parent 6676db3525
commit 7f09c47ffb

View file

@ -66,8 +66,8 @@ static void calc_collision_pos(
boxAABB.b.y -= stepHeight + E * 2; boxAABB.b.y -= stepHeight + E * 2;
if (box->position[nx] > pos[nx] && box->getAABB().intersects(boxAABB)) { if (box->position[nx] > pos[nx] && box->getAABB().intersects(boxAABB)) {
float newnegx = box->position[nx] - boxhalf[nx] - half[nx] - E; float newnegx = box->position[nx] - boxhalf[nx] - half[nx];
float newposx = box->position[nx] + boxhalf[nx] + half[nx] + E; float newposx = box->position[nx] + boxhalf[nx] + half[nx];
float newx; float newx;
if (glm::abs(newnegx - pos[nx]) < glm::abs(newposx - pos[nx])) { if (glm::abs(newnegx - pos[nx]) < glm::abs(newposx - pos[nx])) {
newx = newnegx; newx = newnegx;
@ -79,7 +79,6 @@ static void calc_collision_pos(
vel[nx] = 0.0f; vel[nx] = 0.0f;
} }
pos[nx] = newx; pos[nx] = newx;
collided[nx] = true;
} }
} }
} }
@ -138,8 +137,8 @@ static void calc_collision_neg(
boxAABB.b.y -= stepHeight + E * 2; boxAABB.b.y -= stepHeight + E * 2;
if (box->position[nx] < pos[nx] && box->getAABB().intersects(boxAABB)) { if (box->position[nx] < pos[nx] && box->getAABB().intersects(boxAABB)) {
float newnegx = box->position[nx] - boxhalf[nx] - half[nx] - E; float newnegx = box->position[nx] - boxhalf[nx] - half[nx];
float newposx = box->position[nx] + boxhalf[nx] + half[nx] + E; float newposx = box->position[nx] + boxhalf[nx] + half[nx];
float newx; float newx;
if (glm::abs(newnegx - pos[nx]) > glm::abs(newposx - pos[nx])) { if (glm::abs(newnegx - pos[nx]) > glm::abs(newposx - pos[nx])) {
newx = newposx; newx = newposx;
@ -151,7 +150,6 @@ static void calc_collision_neg(
vel[nx] = 0.0f; vel[nx] = 0.0f;
} }
pos[nx] = newx; pos[nx] = newx;
collided[nx] = true;
} }
} }
} }
@ -448,7 +446,7 @@ void PhysicsSolver::step(
calcSubstep(chunks, hitbox, vel, pos, prevGrounded, dt); calcSubstep(chunks, hitbox, vel, pos, prevGrounded, dt);
} }
if (prevGrounded && !hitbox.grounded && vel.y <= 0.0f) { if (prevGrounded && !hitbox.grounded) {
vel += hitbox.groundVelocity; vel += hitbox.groundVelocity;
hitbox.groundVelocity = {}; hitbox.groundVelocity = {};
} }