Browse Source

better collision

feature/replace-renderer
Martin Dørum 3 years ago
parent
commit
8b9076547b
1 changed files with 5 additions and 5 deletions
  1. 5
    5
      libswan/src/traits/PhysicsTrait.cc

+ 5
- 5
libswan/src/traits/PhysicsTrait.cc View File

@@ -4,7 +4,7 @@

namespace Swan {

static float epsilon = 0.0001;
static float epsilon = 0.05;

static void collideX(
PhysicsTrait::Physics &phys, BodyTrait::Body &body,
@@ -12,7 +12,7 @@ static void collideX(
bool collided = false;

for (int y = (int)floor(body.top() + epsilon); y <= (int)floor(body.bottom() - epsilon); ++y) {
int lx = (int)floor(body.left() + epsilon);
int lx = (int)floor(body.left());
Tile &left = plane.getTile({lx, y});
if (left.isSolid) {
body.pos.x = (float)lx + 1.0;
@@ -20,7 +20,7 @@ static void collideX(
break;
}

int rx = (int)floor(body.right() - epsilon);
int rx = (int)floor(body.right());
Tile &right = plane.getTile({rx, y});
if (right.isSolid) {
body.pos.x = (float)rx - body.size.x;
@@ -43,7 +43,7 @@ static void collideY(
phys.onGround = false;

for (int x = (int)floor(body.left() + epsilon); x <= (int)floor(body.right() - epsilon); ++x) {
int ty = (int)floor(body.top() + epsilon);
int ty = (int)floor(body.top());
Tile &top = plane.getTile({x, ty});
if (top.isSolid) {
body.pos.y = (float)ty + 1.0;
@@ -51,7 +51,7 @@ static void collideY(
break;
}

int by = (int)floor(body.bottom() - epsilon);
int by = (int)floor(body.bottom());
Tile &bottom = plane.getTile({x, by});
if (bottom.isSolid) {
body.pos.y = (float)by - body.size.y;

Loading…
Cancel
Save