Skip to content

Commit e429363

Browse files
committed
Test previous difference too, to mitigate tunneling
1 parent 395e4d0 commit e429363

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/physics/arcade/GetOverlapY.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ var GetOverlapY = function (body1, body2, overlapOnly, bias)
3232

3333
var distance1 = body1.bottom - body2.y;
3434
var distance2 = body2.bottom - body1.y;
35+
var prevDistance1 = (body1.prev.y + body1.height) - body2.y;
36+
var prevDistance2 = body2.bottom - body2.prev.y;
3537

3638
var blocked1 = body1.blocked;
3739
var blocked2 = body2.blocked;
3840

39-
var topFace = false;
41+
var topFace = (distance1 > distance2 && prevDistance1 > prevDistance2);
4042

41-
if (distance1 < distance2)
43+
if (!topFace)
4244
{
43-
// Less intersection between the bottom of body1 and the top of body2
45+
// body1 bottom is touching body2 top
4446
overlap = distance1;
4547

4648
if ((overlap > maxOverlap && !overlapOnly) || !body1.checkCollision.down || !body2.checkCollision.up)
@@ -65,9 +67,8 @@ var GetOverlapY = function (body1, body2, overlapOnly, bias)
6567
}
6668
else
6769
{
68-
// Less intersection between the top of body1 and the bottom of body2
70+
// body1 top is touching body2 bottom
6971
overlap = distance2;
70-
topFace = true;
7172

7273
if ((overlap > maxOverlap && !overlapOnly) || !body1.checkCollision.up || !body2.checkCollision.down)
7374
{

0 commit comments

Comments
 (0)