From e7002146fd9786f808481849025af20f074190a1 Mon Sep 17 00:00:00 2001 From: dawsh Date: Thu, 12 Jun 2025 15:00:54 -0500 Subject: [PATCH] Tuning collision math. --- testgame.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/testgame.cpp b/testgame.cpp index dc69d10..775c9f0 100644 --- a/testgame.cpp +++ b/testgame.cpp @@ -46,6 +46,11 @@ public: // This means we can collision solve our next_pos in between calls to entity->Update(); pos = next_pos; + const float gravity = 9.8f; + const float mass = 1.f; + + velocity.y += (elapsed*gravity*mass); + float constant_move_spd = 40; if (InputService::IsKeyDown(Keys::A)) @@ -163,25 +168,22 @@ public: int cell_width = layer->cell_width; int cell_height = layer->cell_height; - int ent_tile_tl_x = Math::Floor(entity->pos.x / cell_width); - int ent_tile_tl_y = Math::Floor(entity->pos.y / cell_height); + int ent_tile_tl_x = Math::Floor(entity->next_pos.x) / cell_width; + int ent_tile_tl_y = Math::Floor(entity->next_pos.y) / cell_height; - int occupies_h_tiles = Math::Floor(entity->bbox.x / cell_width); - int occupies_v_tiles = Math::Floor(entity->bbox.y / cell_height); + int occupies_h_tiles = Math::Floor(entity->bbox.x) / cell_width; + int occupies_v_tiles = Math::Floor(entity->bbox.y) / cell_height; Vector2 cell_bbox = Vector2(layer->cell_width, layer->cell_height); - for (int x = -1; x <= occupies_h_tiles; x++) { - for (int y = -1; y <= occupies_v_tiles; y++) { - + for (int x = -1; x <= occupies_h_tiles+1; x++) { + for (int y = -1; y <= occupies_v_tiles+1; y++) { int cell_x = ent_tile_tl_x + x; int cell_y = ent_tile_tl_y + y; - Vector2 cell_topleft = Vector2(cell_x, cell_y) * cell_bbox; - - Vector2i cell_i = Vector2i(cell_x, cell_y); + Vector2 cell_topleft = Vector2(cell_x*cell_width, cell_y*cell_height); if (cell_x < 0) continue; // Out of bounds to the left. if (cell_y < 0) continue; // Out of bounds to the top. @@ -211,7 +213,7 @@ public: Vector2 normal = Solver::GetNormalForAABB(separation, entity->velocity); - if (normal.x == 0 && normal.y == 0) continue; // Why though? + //if (normal.x == 0 && normal.y == 0) continue; // Why though? // Touched top. if (normal.y == -1) { }