Skip to content

Commit f494c86

Browse files
committed
Fixed an issue in the Arcade Physics overlap method where it would only detect overlaps up to the max bias threshold and no further (thanks @rgk phaserjs#2441)
The Arcade Physics overlap method would return false if two bodies were overlapping but neither had any velocity (i.e. they were embedded into each other)
1 parent 620b95e commit f494c86

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,11 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
348348
* TypeScript definitions fixes and updates (thanks )
349349
* Docs typo fixes (thanks )
350350
* You can now access the intensity of the Camera shake effect via the getter / setter `Camera.shakeIntensity`. Useful if you wish to tween the intensity while running. (thanks @drhayes #2443)
351+
* The Arcade Physics overlap method would return false if two bodies were overlapping but neither had any velocity (i.e. they were embedded into each other)
351352

352353
### Bug Fixes
353354

354-
*
355+
* Fixed an issue in the Arcade Physics overlap method where it would only detect overlaps up to the max bias threshold and no further (thanks @rgk #2441)
355356
*
356357
*
357358

src/physics/arcade/World.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,10 @@ Phaser.Physics.Arcade.prototype = {
10181018
* @method Phaser.Physics.Arcade#getOverlapX
10191019
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate.
10201020
* @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate.
1021+
* @param {boolean} overlapOnly - Is this an overlap only check, or part of separation?
10211022
* @return {float} Returns the amount of horizontal overlap between the two bodies.
10221023
*/
1023-
getOverlapX: function (body1, body2) {
1024+
getOverlapX: function (body1, body2, overlapOnly) {
10241025

10251026
var overlap = 0;
10261027
var maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS;
@@ -1036,7 +1037,7 @@ Phaser.Physics.Arcade.prototype = {
10361037
// Body1 is moving right and / or Body2 is moving left
10371038
overlap = body1.right - body2.x;
10381039

1039-
if ((overlap > maxOverlap) || body1.checkCollision.right === false || body2.checkCollision.left === false)
1040+
if ((overlap > maxOverlap && !overlapOnly) || body1.checkCollision.right === false || body2.checkCollision.left === false)
10401041
{
10411042
overlap = 0;
10421043
}
@@ -1053,7 +1054,7 @@ Phaser.Physics.Arcade.prototype = {
10531054
// Body1 is moving left and/or Body2 is moving right
10541055
overlap = body1.x - body2.width - body2.x;
10551056

1056-
if ((-overlap > maxOverlap) || body1.checkCollision.left === false || body2.checkCollision.right === false)
1057+
if ((-overlap > maxOverlap && !overlapOnly) || body1.checkCollision.left === false || body2.checkCollision.right === false)
10571058
{
10581059
overlap = 0;
10591060
}
@@ -1081,9 +1082,10 @@ Phaser.Physics.Arcade.prototype = {
10811082
* @method Phaser.Physics.Arcade#getOverlapY
10821083
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate.
10831084
* @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate.
1085+
* @param {boolean} overlapOnly - Is this an overlap only check, or part of separation?
10841086
* @return {float} Returns the amount of vertical overlap between the two bodies.
10851087
*/
1086-
getOverlapY: function (body1, body2) {
1088+
getOverlapY: function (body1, body2, overlapOnly) {
10871089

10881090
var overlap = 0;
10891091
var maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS;
@@ -1099,7 +1101,7 @@ Phaser.Physics.Arcade.prototype = {
10991101
// Body1 is moving down and/or Body2 is moving up
11001102
overlap = body1.bottom - body2.y;
11011103

1102-
if ((overlap > maxOverlap) || body1.checkCollision.down === false || body2.checkCollision.up === false)
1104+
if ((overlap > maxOverlap && !overlapOnly) || body1.checkCollision.down === false || body2.checkCollision.up === false)
11031105
{
11041106
overlap = 0;
11051107
}
@@ -1116,7 +1118,7 @@ Phaser.Physics.Arcade.prototype = {
11161118
// Body1 is moving up and/or Body2 is moving down
11171119
overlap = body1.y - body2.bottom;
11181120

1119-
if ((-overlap > maxOverlap) || body1.checkCollision.up === false || body2.checkCollision.down === false)
1121+
if ((-overlap > maxOverlap && !overlapOnly) || body1.checkCollision.up === false || body2.checkCollision.down === false)
11201122
{
11211123
overlap = 0;
11221124
}
@@ -1149,13 +1151,13 @@ Phaser.Physics.Arcade.prototype = {
11491151
*/
11501152
separateX: function (body1, body2, overlapOnly) {
11511153

1152-
var overlap = this.getOverlapX(body1, body2);
1154+
var overlap = this.getOverlapX(body1, body2, overlapOnly);
11531155

11541156
// Can't separate two immovable bodies, or a body with its own custom separation logic
11551157
if (overlapOnly || overlap === 0 || (body1.immovable && body2.immovable) || body1.customSeparateX || body2.customSeparateX)
11561158
{
11571159
// return true if there was some overlap, otherwise false
1158-
return (overlap !== 0);
1160+
return (overlap !== 0) || (body1.embedded && body2.embedded);
11591161
}
11601162

11611163
// Adjust their positions and velocities accordingly (if there was any overlap)
@@ -1219,13 +1221,13 @@ Phaser.Physics.Arcade.prototype = {
12191221
*/
12201222
separateY: function (body1, body2, overlapOnly) {
12211223

1222-
var overlap = this.getOverlapY(body1, body2);
1224+
var overlap = this.getOverlapY(body1, body2, overlapOnly);
12231225

12241226
// Can't separate two immovable bodies, or a body with its own custom separation logic
12251227
if (overlapOnly || overlap === 0 || (body1.immovable && body2.immovable) || body1.customSeparateY || body2.customSeparateY)
12261228
{
12271229
// return true if there was some overlap, otherwise false
1228-
return (overlap !== 0);
1230+
return (overlap !== 0) || (body1.embedded && body2.embedded);
12291231
}
12301232

12311233
// Adjust their positions and velocities accordingly (if there was any overlap)

0 commit comments

Comments
 (0)