Fix bus collision with smashed items by clearing bus category from item mask
This commit is contained in:
parent
f4b89a25df
commit
d9b6a754d8
|
|
@ -383,6 +383,12 @@ export default {
|
||||||
] },
|
] },
|
||||||
],
|
],
|
||||||
obstacles: [],
|
obstacles: [],
|
||||||
|
items: [
|
||||||
|
{ type: "tv", mode: "gravity", x: 5754, y: 444 },
|
||||||
|
{ type: "cone", mode: "gravity", x: 2479, y: 369 },
|
||||||
|
{ type: "cone", mode: "gravity", x: 2721, y: 219 },
|
||||||
|
{ type: "cone", mode: "gravity", x: 2521, y: 136 },
|
||||||
|
],
|
||||||
goal: { x: 25420, y: 406, width: 280, height: 640 },
|
goal: { x: 25420, y: 406, width: 280, height: 640 },
|
||||||
cameraBounds: { x: -600, y: -522, width: 27060, height: 2414 },
|
cameraBounds: { x: -600, y: -522, width: 27060, height: 2414 },
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -112,11 +112,24 @@ export default class SmashItemManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The smash: swap to the smashed frame, make the body dynamic (so the
|
// The smash: swap to the smashed frame, make the body dynamic (so the
|
||||||
// launch actually moves it), and give it the up-and-forward impulse.
|
// launch actually moves it), give it the up-and-forward impulse, and clear
|
||||||
|
// the bus out of its collision mask so the bus drives straight through it.
|
||||||
_smash(item) {
|
_smash(item) {
|
||||||
const image = item.image;
|
const image = item.image;
|
||||||
const dirX = Math.sign(this.bus.chassis.body.velocity.x) >= 0 ? 1 : -1;
|
const dirX = Math.sign(this.bus.chassis.body.velocity.x) >= 0 ? 1 : -1;
|
||||||
|
|
||||||
|
// From this moment on the smashed item is no longer solid to the bus.
|
||||||
|
// Clear the bus's category bit out of the item's collision mask so the
|
||||||
|
// broadphase skips every item<->bus pair (Detector.canCollide only
|
||||||
|
// considers a pair when each side's mask includes the other's category -
|
||||||
|
// see the vendored build). Set on the raw matter body directly: that's the
|
||||||
|
// exact field canCollide reads, and matter-js recomputes pairs every step,
|
||||||
|
// so this takes effect on the very next physics step. The item keeps its
|
||||||
|
// mask against everything ELSE (terrain, other items, kids), so it still
|
||||||
|
// lands and rests where it flies - only the bus is exempted. This is what
|
||||||
|
// makes the bus "drive through" a smashed prop instead of bumping it.
|
||||||
|
image.body.collisionFilter.mask = 0xffffffff & ~this.bus.busCategory;
|
||||||
|
|
||||||
// setStatic(false) (Phaser component, same as in _buildItem) restores
|
// setStatic(false) (Phaser component, same as in _buildItem) restores
|
||||||
// the body's saved real mass/inertia - matter-js stashed them when the
|
// the body's saved real mass/inertia - matter-js stashed them when the
|
||||||
// body was made static - so the velocity math below is meaningful. For
|
// body was made static - so the velocity math below is meaningful. For
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue