Tuning collision math.

This commit is contained in:
2025-06-12 15:00:54 -05:00
parent 2e4e8b20a7
commit e7002146fd

View File

@@ -46,6 +46,11 @@ public:
// This means we can collision solve our next_pos in between calls to entity->Update(); // This means we can collision solve our next_pos in between calls to entity->Update();
pos = next_pos; pos = next_pos;
const float gravity = 9.8f;
const float mass = 1.f;
velocity.y += (elapsed*gravity*mass);
float constant_move_spd = 40; float constant_move_spd = 40;
if (InputService::IsKeyDown(Keys::A)) if (InputService::IsKeyDown(Keys::A))
@@ -163,25 +168,22 @@ public:
int cell_width = layer->cell_width; int cell_width = layer->cell_width;
int cell_height = layer->cell_height; int cell_height = layer->cell_height;
int ent_tile_tl_x = Math::Floor(entity->pos.x / cell_width); int ent_tile_tl_x = Math::Floor(entity->next_pos.x) / cell_width;
int ent_tile_tl_y = Math::Floor(entity->pos.y / cell_height); 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_h_tiles = Math::Floor(entity->bbox.x) / cell_width;
int occupies_v_tiles = Math::Floor(entity->bbox.y / cell_height); int occupies_v_tiles = Math::Floor(entity->bbox.y) / cell_height;
Vector2 cell_bbox = Vector2(layer->cell_width, layer->cell_height); Vector2 cell_bbox = Vector2(layer->cell_width, layer->cell_height);
for (int x = -1; x <= occupies_h_tiles; x++) { for (int x = -1; x <= occupies_h_tiles+1; x++) {
for (int y = -1; y <= occupies_v_tiles; y++) { for (int y = -1; y <= occupies_v_tiles+1; y++) {
int cell_x = ent_tile_tl_x + x; int cell_x = ent_tile_tl_x + x;
int cell_y = ent_tile_tl_y + y; int cell_y = ent_tile_tl_y + y;
Vector2 cell_topleft = Vector2(cell_x, cell_y) * cell_bbox; Vector2 cell_topleft = Vector2(cell_x*cell_width, cell_y*cell_height);
Vector2i cell_i = Vector2i(cell_x, cell_y);
if (cell_x < 0) continue; // Out of bounds to the left. if (cell_x < 0) continue; // Out of bounds to the left.
if (cell_y < 0) continue; // Out of bounds to the top. if (cell_y < 0) continue; // Out of bounds to the top.
@@ -211,7 +213,7 @@ public:
Vector2 normal = Solver::GetNormalForAABB(separation, entity->velocity); 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. // Touched top.
if (normal.y == -1) { } if (normal.y == -1) { }