From 6b1f9d73545938f0e827a4b1da45fb7bd6c225ec Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Sun, 2 Aug 2026 17:14:13 +0800 Subject: [PATCH] feat(physics): implement step-up for horizontal collisions --- src/gameplay/systems/physical_system.cpp | 43 +++++++++++++++++++----- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/gameplay/systems/physical_system.cpp b/src/gameplay/systems/physical_system.cpp index bd4a4db..fc2eda5 100644 --- a/src/gameplay/systems/physical_system.cpp +++ b/src/gameplay/systems/physical_system.cpp @@ -111,25 +111,52 @@ void PhysicalSystem::update(ServerWorld& world, entt::registry& registry) { auto box = HitboxManager::hitbox(creature.hitbox); auto& pos = creature.transform.position.value; auto& v = creature.velocity; - if (update_x(pos, distance, world, box.box)) { - pos.x += distance.x; - - } else { - v.value.x = 0.0f; - } - + bool ground = + !update_y(pos, glm::vec3{0.0f, -0.1f, 0.0f}, world, box.box); + bool stepped = false; if (update_y(pos, distance, world, box.box)) { pos.y += distance.y; } else { v.value.y = 0.0f; } + if (update_x(pos, distance, world, box.box)) { + pos.x += distance.x; + + } else { + if (ground && !stepped) { + + glm::vec3 step_pos = pos + glm::vec3{0.0f, 1.0f, 0.0f}; + if (update_x(step_pos, distance, world, box.box)) { + pos.x += distance.x; + pos.y += 1.0f; + stepped = true; + } else { + v.value.x = 0.0f; + } + } else { + v.value.x = 0.0f; + } + } if (update_z(pos, distance, world, box.box)) { pos.z += distance.z; } else { - v.value.z = 0.0f; + if (ground && !stepped) { + + glm::vec3 step_pos = pos + glm::vec3{0.0f, 1.0f, 0.0f}; + if (update_z(step_pos, distance, world, box.box)) { + pos.z += distance.z; + pos.y += 1.0f; + stepped = true; + + } else { + v.value.z = 0.0f; + } + } else { + v.value.z = 0.0f; + } } } }