Created
December 5, 2021 12:25
-
-
Save shohan4556/6f2a03bbd12efded7f1ea228161781a0 to your computer and use it in GitHub Desktop.
check overlap without physics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const position = getRelativePositionToParcel(parcel, worldPosition); | |
console.log('relativePosition', position); | |
if (parcel && !isOverlap(parcel, position)) { | |
} | |
function getRelativePositionToParcel({ bounds }, pxPosition) { | |
// Return position top_left position in InstallationGrid | |
return { | |
x: (pxPosition.x - bounds.x) / GOTCHI, | |
y: (pxPosition.y - bounds.y) / GOTCHI, | |
}; | |
} | |
function isOverlap({ grid }: Parcel, relativePosition: Vector2): boolean { | |
let isOverlap = false; | |
if (grid !== undefined) { | |
for (let y = relativePosition.y; y < relativePosition.y + selectedInstallation.height; y++) { | |
for (let x = relativePosition.x; x < relativePosition.x + selectedInstallation.width; x++) { | |
if (grid[y][x] !== 0) { | |
console.log('grid', grid[y][x]); | |
isOverlap = true; | |
break; | |
} | |
} | |
} | |
return isOverlap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment