From 25b7dacb08e5982e3b24b6b3d52bab1283ba105e Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 11 Aug 2023 13:37:47 +0900 Subject: [PATCH] Refactor y-pos caluclation when Walker moves --- src/walker.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/walker.h b/src/walker.h index 850cdd1..80b8fa8 100644 --- a/src/walker.h +++ b/src/walker.h @@ -90,12 +90,10 @@ void Walker::update(float dt, const TBBS &bbs, unsigned int width, float y = 0.0F; float z = (float)(idx / width) - SURFACE_Y_OFFSET; - Ray downwards{.position = Vector3{x, 20.0F, z}, + Ray downwards{.position = Vector3{x, bbs[idx].max.y + 1.0F, z}, .direction = Vector3{0.0F, -1.0F, 0.0F}}; - for (const auto &bb : bbs) { - if (GetRayCollisionBox(downwards, bb).hit) { - y = (bb.min.y + bb.max.y) / 2.0F; - } + if (GetRayCollisionBox(downwards, bbs[idx]).hit) { + y = (bbs[idx].min.y + bbs[idx].max.y) / 2.0F; } set_body_pos(Vector3{x, y, z});