feat(physics): implement step-up for horizontal collisions

This commit is contained in:
2026-08-02 17:14:13 +08:00
parent 5980400e2e
commit 6b1f9d7354

View File

@@ -111,26 +111,53 @@ 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 {
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;
}
}
}
}