diff --git a/src/physics/Hitbox.hpp b/src/physics/Hitbox.hpp index 7cc828e7a..80c628491 100644 --- a/src/physics/Hitbox.hpp +++ b/src/physics/Hitbox.hpp @@ -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; } }; diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index 8992d89e1..6cf5ac62e 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -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;