diff --git a/src/collision/CollisionSurface.hx b/src/collision/CollisionSurface.hx index ac73ca01..4d3dc8b6 100644 --- a/src/collision/CollisionSurface.hx +++ b/src/collision/CollisionSurface.hx @@ -155,8 +155,8 @@ class CollisionSurface implements IOctreeObject implements IBVHObject { if (t < bestT) { bestT = t; intersections.push({ - point: ip, - normal: n, + point: ip.clone(), + normal: n.clone(), object: cast this, t: t }); diff --git a/src/collision/Grid.hx b/src/collision/Grid.hx index 3af6df69..92f6f6cf 100644 --- a/src/collision/Grid.hx +++ b/src/collision/Grid.hx @@ -128,27 +128,36 @@ class Grid { var cell = origin.sub(this.bounds.getMin().toVector()); cell.x /= this.cellSize.x; cell.y /= this.cellSize.y; + var destCell = origin.add(direction.multiply(bestT)).sub(this.bounds.getMin().toVector()); + destCell.x /= this.cellSize.x; + destCell.y /= this.cellSize.y; var stepX, outX, X = Math.floor(cell.x); var stepY, outY, Y = Math.floor(cell.y); + var destX = Math.max(Math.floor(destCell.x), 0); + var destY = Math.max(Math.floor(destCell.y), 0); if ((X < 0) || (X >= CELL_DIV.x) || (Y < 0) || (Y >= CELL_DIV.y)) return []; var cb = new Vector(); if (direction.x > 0) { stepX = 1; - outX = CELL_DIV.x; + outX = destX; + if (outX == X) + outX = Math.min(CELL_DIV.x, outX + 1); cb.x = this.bounds.xMin + (X + 1) * this.cellSize.x; } else { stepX = -1; - outX = -1; + outX = destX - 1; cb.x = this.bounds.xMin + X * this.cellSize.x; } if (direction.y > 0.0) { stepY = 1; - outY = CELL_DIV.y; + outY = destY; + if (outY == Y) + outY = Math.min(CELL_DIV.y, outY + 1); cb.y = this.bounds.yMin + (Y + 1) * this.cellSize.y; } else { stepY = -1; - outY = -1; + outY = destY - 1; cb.y = this.bounds.yMin + Y * this.cellSize.y; } var tmax = new Vector(); diff --git a/src/collision/SphereCollisionEntity.hx b/src/collision/SphereCollisionEntity.hx index 4a90c190..06892285 100644 --- a/src/collision/SphereCollisionEntity.hx +++ b/src/collision/SphereCollisionEntity.hx @@ -93,10 +93,10 @@ class SphereCollisionEntity extends CollisionEntity { contact.collider = this; contact.friction = 1; contact.restitution = 1; - contact.velocity = this.velocity.clone(); + contact.velocity.load(this.velocity); contact.otherObject = this.go; - contact.point = position.add(normDist); - contact.normal = normDist.multiply(-1); + contact.point.load(position.add(normDist)); + contact.normal.load(normDist.multiply(-1)); contact.force = 0; contact.contactDistance = contact.point.distance(position); contacts.push(contact);