Skip to content

Commit 9577f3e

Browse files
committed
Added condition to resolve fast moving body penetration hitting the wrong face
1 parent 2317cb2 commit 9577f3e

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/physics/arcade/CollisionInfo.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ var CollisionInfo = {
104104
faceX = CONST.FACING_LEFT;
105105

106106
// body1 left is touching body2 right
107-
// if (intersectsX && body1.checkCollision.left && body2.checkCollision.right)
108107
if (intersectsX)
109108
{
110109
overlapX = distanceX2;
@@ -138,7 +137,6 @@ var CollisionInfo = {
138137
faceX = CONST.FACING_RIGHT;
139138

140139
// body1 right is touching body2 left
141-
// if (intersectsX && body1.checkCollision.right && body2.checkCollision.left)
142140
if (intersectsX)
143141
{
144142
overlapX = distanceX1;
@@ -173,7 +171,6 @@ var CollisionInfo = {
173171
faceY = CONST.FACING_UP;
174172

175173
// body1 top is touching body2 bottom
176-
// if (intersectsY && body1.checkCollision.up && body2.checkCollision.down)
177174
if (intersectsY)
178175
{
179176
overlapY = distanceY2;
@@ -207,7 +204,6 @@ var CollisionInfo = {
207204
faceY = CONST.FACING_DOWN;
208205

209206
// body1 bottom is touching body2 top
210-
// if (intersectsY && body1.checkCollision.down && body2.checkCollision.up)
211207
if (intersectsY)
212208
{
213209
overlapY = distanceY1;
@@ -238,6 +234,17 @@ var CollisionInfo = {
238234
}
239235

240236
var forceX = (touchingX || overlapX < overlapY);
237+
238+
// Swizzle it if the body was moving so fast the penetration is too deep to resolve using faces alone
239+
if (forceX && (maxOverlapY >= maxOverlapX))
240+
{
241+
forceX = false;
242+
}
243+
else if (!forceX && (maxOverlapX >= maxOverlapY))
244+
{
245+
forceX = true;
246+
}
247+
241248
var face = (forceX) ? faceX : faceY;
242249

243250
if (forceX && FuzzyEqual(overlapX, 0))
@@ -281,7 +288,11 @@ var CollisionInfo = {
281288
var v1 = body1.velocity;
282289
var v2 = body2.velocity;
283290

284-
if (!checkCollision1.left && (face === CONST.FACING_LEFT && v2.x >= 0))
291+
if (checkCollision1.none || checkCollision2.none)
292+
{
293+
abort = true;
294+
}
295+
else if (!checkCollision1.left && (face === CONST.FACING_LEFT && v2.x >= 0))
285296
{
286297
abort = true;
287298
}

0 commit comments

Comments
 (0)