Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MBR narrow-phase collision logic #1168

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spatial/collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ Crafty.c("Collision", {
SAT.obj = obj;
SAT.type = "SAT";
}
} else if (Crafty.rectManager.overlap(area, this._cbr || this._mbr || this)){
} else if (Crafty.rectManager.overlap(area, obj._cbr || obj._mbr || obj)){
results.push({
obj: obj,
type: "MBR"
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/spatial/collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@
_.ok('overlap' in results[0], "expected overlap value");
});

test("hit -- collision vs. non collision tests", function(_){
var e1 = Crafty.e("2D, Collision")
.attr({x: 0, y: 0, w: 2, h: 2});
var e2 = Crafty.e("2D")
.attr({x: 0, y: 0, w: 2, h: 2});
var results = e1.hit('2D');
_.strictEqual(results.length, 1, "exactly one collision");
_.strictEqual(results[0].type, "MBR", "expecdted MBR collision type");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo 😅

_.strictEqual(results[0].obj[0], e2[0], "Expected collision with e2");

// Move e2 such that it should be returned by the broadphase search, but should not be considered a hit
e2.x=3;
var newResults = e1.hit('2D');
_.ok(!newResults, 0, "No collisions");
});

test("onHit", function(_) {
var e = Crafty.e("2D, Collision")
.attr({x: 0, y: 0, w: 25, h: 25});
Expand Down