fix division by zero in some cases

This commit is contained in:
MihailRis 2026-03-06 19:47:43 +03:00
parent 6f195c9a2c
commit 7d09a7957c
2 changed files with 24 additions and 11 deletions

View file

@ -140,8 +140,10 @@ static bool calc_collision_neg_y(
if (pos.y < newy && glm::abs(pos.y - newy) < 0.5f) {
pos.y = newy;
}
hitbox.groundVelocity =
(box->position - box->prevPosition) / box->delta;
if (glm::abs(box->delta) > 1e-5f) {
hitbox.groundVelocity =
(box->position - box->prevPosition) / box->delta;
}
if (vel.y < 0.0f) {
vel.y = 0.0f;
if (hitbox.groundMaterial.empty()) {
@ -300,6 +302,9 @@ void PhysicsSolver::calcSubstep(
) {
if (hitbox.grounded) {
pos.x += hitbox.groundVelocity.x * dt * substeps;
if (hitbox.groundVelocity.y < 0.0f) {
pos.y += hitbox.groundVelocity.y * dt * substeps;
}
pos.z += hitbox.groundVelocity.z * dt * substeps;
}