Skip to content

Commit 19bfe38

Browse files
committed
Resolved issue with bounds penetration (finally)
1 parent 9ac70e3 commit 19bfe38

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ var Body = new Class({
10491049
// console.log(this.world._frame, 'UP Y', velocity.y, position.y, this.prev.y, this.blockers.length);
10501050
// }
10511051

1052-
if (this.collideWorldBounds)
1052+
if (this.collideWorldBounds && !this.worldBlocked.none)
10531053
{
10541054
this.checkWorldRebound();
10551055
}
@@ -1315,6 +1315,8 @@ var Body = new Class({
13151315
if (!this.collideWorldBounds || worldBlocked.none || velocity.equals(0) || (bx === 0 && by === 0))
13161316
{
13171317
// Nothing to do
1318+
console.log('CWB abort', this.collideWorldBounds, worldBlocked.none, velocity.equals(0));
1319+
13181320
return true;
13191321
}
13201322

@@ -1498,15 +1500,18 @@ var Body = new Class({
14981500
*/
14991501
checkWorldBounds: function ()
15001502
{
1503+
var velocity = this.velocity;
15011504
var worldBounds = this.world.bounds;
15021505
var worldCollision = this.world.checkCollision;
15031506

1504-
if (worldCollision.up && this.y <= (worldBounds.y + 1))
1507+
if (worldCollision.up && this.y <= (worldBounds.y + 1) && velocity.y <= 0)
15051508
{
15061509
this.setWorldBlockedUp(true);
15071510
}
1508-
else if (worldCollision.down && this.bottom >= (worldBounds.bottom - 1))
1511+
else if (worldCollision.down && this.bottom >= (worldBounds.bottom - 1) && velocity.y >= 0)
15091512
{
1513+
// console.log(this.world._frame, 'via check world bounds');
1514+
15101515
this.setWorldBlockedDown(true);
15111516
}
15121517
},
@@ -2314,9 +2319,11 @@ var Body = new Class({
23142319

23152320
if (forceY && this.bottom !== worldBounds.bottom)
23162321
{
2317-
console.log(this.gameObject.name, 'world blocked down + position');
23182322
this.bottom = worldBounds.bottom;
2323+
23192324
this.forcePosition = 2;
2325+
2326+
console.log(this.world._frame, this.gameObject.name, 'world blocked down + position', this.y);
23202327
}
23212328

23222329
return this;
@@ -2435,15 +2442,21 @@ var Body = new Class({
24352442

24362443
if (amount < 0 && worldCollision.up && this.y + amount < worldBounds.y)
24372444
{
2445+
var diff1 = amount - ((this.y + amount) - worldBounds.y);
2446+
24382447
this.setWorldBlockedUp(true);
24392448

2440-
return amount - ((this.y + amount) - worldBounds.y);
2449+
return diff1;
24412450
}
24422451
else if (amount > 0 && worldCollision.down && this.bottom + amount > worldBounds.bottom)
24432452
{
2453+
var diff2 = amount - ((this.bottom + amount) - worldBounds.bottom);
2454+
2455+
// console.log(this.world._frame, 'via check get move y');
2456+
24442457
this.setWorldBlockedDown(true);
24452458

2446-
return amount - ((this.bottom + amount) - worldBounds.bottom);
2459+
return diff2;
24472460
}
24482461
}
24492462

0 commit comments

Comments
 (0)