From 01d46b2690b700630e0f456459e53ab63f2a82fb Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 5 Mar 2026 20:34:35 +0300 Subject: [PATCH] add groundMaterial --- src/physics/Hitbox.hpp | 4 +++- src/physics/PhysicsSolver.cpp | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/physics/Hitbox.hpp b/src/physics/Hitbox.hpp index 0539f90f3..15b7acc89 100644 --- a/src/physics/Hitbox.hpp +++ b/src/physics/Hitbox.hpp @@ -64,11 +64,13 @@ struct Hitbox { float gravityScale = 1.0f; bool crouching = false; float stepHeight = 0.5f; + std::string material; + glm::vec3 groundVelocity {}; + std::string groundMaterial; // garbage tbh glm::vec3 prevPosition {}; - int substeps = 1; float delta = 0.0f; static inline constexpr float TELEPORT_THRESOLD_SQR = 0.5f; diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index 3e260d4bd..cfddcb783 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -116,13 +116,14 @@ static void calc_collision( } static bool calc_collision_neg_y( + Hitbox& hitbox, const GlobalChunks& chunks, const std::vector& solidHitboxes, - glm::vec3& pos, - glm::vec3& vel, - const glm::vec3& half, - glm::vec3& groundVelocty + const glm::vec3& half ) { + auto& pos = hitbox.position; + auto& vel = hitbox.velocity; + for (auto box : solidHitboxes) { if (glm::distance2(box->position, pos) < E) { continue; @@ -139,9 +140,13 @@ static bool calc_collision_neg_y( if (pos.y < newy && glm::abs(pos.y - newy) < 0.5f) { pos.y = newy; } - groundVelocty = (box->position - box->prevPosition) / box->delta; + hitbox.groundVelocity = + (box->position - box->prevPosition) / box->delta; if (vel.y < 0.0f) { vel.y = 0.0f; + if (hitbox.groundMaterial.empty()) { + hitbox.groundMaterial = hitbox.material; + } return true; } } @@ -149,7 +154,7 @@ static bool calc_collision_neg_y( if (vel.y >= 0.0f) { return false; } - groundVelocty = {}; + hitbox.groundVelocity = {}; for (int ix = 0; ix <= glm::ceil((half.x - E) * 2); ix++) { glm::vec3 coord; coord.x = (pos.x - half.x + E) + ix; @@ -200,7 +205,7 @@ void PhysicsSolver::calcCollisions( calc_collision<2, 1, 0, 1>(hitbox, chunks, solidHitboxes, half, stepHeight); pos.x = xpos; - if (calc_collision_neg_y(chunks, solidHitboxes, pos, vel, half, hitbox.groundVelocity)) { + if (calc_collision_neg_y(hitbox, chunks, solidHitboxes, half)) { hitbox.grounded = true; } @@ -369,8 +374,8 @@ void PhysicsSolver::step( entityid_t entity ) { hitbox.prevPosition = hitbox.position; - hitbox.substeps = substeps; hitbox.delta = delta; + hitbox.groundMaterial.clear(); float dt = delta / static_cast(substeps); float linearDamping = hitbox.linearDamping * hitbox.friction;