This commit is contained in:
MihailRis 2026-03-22 22:32:02 +03:00
parent 1d2c8cf4b6
commit 3ab5095583
2 changed files with 5 additions and 9 deletions

View file

@ -67,10 +67,7 @@ struct Hitbox {
float elasticity = 0.0f;
std::string material;
std::string groundMaterial;
// FIXME: only one must survive
glm::vec3 groundVelocity {};
glm::vec3 actualGroundVelocity {};
glm::vec3 prevPosition {};
glm::vec3 prevVelocity {};
@ -98,6 +95,6 @@ struct Hitbox {
}
glm::vec3 getSurfaceVelocity() const {
return velocity - actualGroundVelocity;
return velocity - groundVelocity;
}
};

View file

@ -166,8 +166,8 @@ bool PhysicsSolver::calcCollisionNegY(
auto velA = calc_collsion_velocity_result(hitbox, *box);
auto velB = calc_collsion_velocity_result(*box, hitbox);
hitbox.groundVelocity = box->position - box->prevPosition;
if (vel.y < hitbox.groundVelocity.y / dt) {
hitbox.groundVelocity = (box->position - box->prevPosition) / dt;
if (vel.y < hitbox.groundVelocity.y) {
vel.y = velA.y;
box->velocity.y = velB.y;
if (hitbox.groundMaterial.empty() && !box->material.empty()) {
@ -267,7 +267,7 @@ void PhysicsSolver::calcCollisions(
}
auto velA = calc_collsion_velocity_result(hitbox, *box);
auto velB = calc_collsion_velocity_result(*box, hitbox);
if (vel.y > hitbox.groundVelocity.y / dt) {
if (vel.y > hitbox.groundVelocity.y) {
vel.y = velA.y;
box->velocity.y = velB.y;
break;
@ -399,8 +399,7 @@ void PhysicsSolver::step(
float linearDamping = hitbox->linearDamping;
glm::vec3& vel = hitbox->velocity;
hitbox->actualGroundVelocity = hitbox->groundVelocity / dt;
auto diff = hitbox->actualGroundVelocity - vel;
auto diff = hitbox->groundVelocity - vel;
vel.x += diff.x * delta * linearDamping;
vel.z += diff.z * delta * linearDamping;