mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-23 04:08:03 +00:00
Enhance NPC collision detection: add checks for table objects in NPC behavior and log successful collisions for better debugging.
This commit is contained in:
@@ -1134,22 +1134,42 @@ class NPCBehavior {
|
||||
}
|
||||
|
||||
const room = window.rooms ? window.rooms[this.roomId] : null;
|
||||
if (!room || !room.wallCollisionBoxes) {
|
||||
return; // No walls to check
|
||||
if (!room) {
|
||||
return; // No room reference
|
||||
}
|
||||
|
||||
// Check if NPC is overlapping with any wall collision box
|
||||
// Check if NPC is overlapping with any wall collision box or table
|
||||
let isOverlappingWall = false;
|
||||
let overlappingWall = null;
|
||||
|
||||
for (const wallBox of room.wallCollisionBoxes) {
|
||||
if (!wallBox.body) continue;
|
||||
// Check walls
|
||||
if (room.wallCollisionBoxes) {
|
||||
for (const wallBox of room.wallCollisionBoxes) {
|
||||
if (!wallBox.body) continue;
|
||||
|
||||
// Check if NPC body overlaps with wall using scene physics
|
||||
if (this.scene.physics.overlap(this.sprite, wallBox)) {
|
||||
isOverlappingWall = true;
|
||||
overlappingWall = wallBox;
|
||||
break;
|
||||
// Check if NPC body overlaps with wall using scene physics
|
||||
if (this.scene.physics.overlap(this.sprite, wallBox)) {
|
||||
isOverlappingWall = true;
|
||||
overlappingWall = wallBox;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check tables (if not already stuck in a wall)
|
||||
if (!isOverlappingWall && room.objects) {
|
||||
for (const obj of Object.values(room.objects)) {
|
||||
if (!obj || !obj.body) continue;
|
||||
|
||||
// Check if this is a table (has scenarioData.type === 'table' or name includes 'desk')
|
||||
const isTable = (obj.scenarioData && obj.scenarioData.type === 'table') ||
|
||||
(obj.name && obj.name.toLowerCase().includes('desk'));
|
||||
|
||||
if (isTable && this.scene.physics.overlap(this.sprite, obj)) {
|
||||
isOverlappingWall = true;
|
||||
overlappingWall = obj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -526,9 +526,9 @@ export function setupNPCTableCollisions(scene, npcSprite, roomId) {
|
||||
|
||||
// Collision with all table objects in the room
|
||||
Object.values(room.objects).forEach(obj => {
|
||||
// Tables are identified by their object name or by checking if they're static bodies
|
||||
// Look for objects that came from the 'table' type in processObject
|
||||
if (obj && obj.body && obj.body.static) {
|
||||
// Tables are identified by scenarioData.type === 'table' or name includes 'desk'
|
||||
// Tables are static collision objects, so they should have a physics body
|
||||
if (obj && obj.body) {
|
||||
// Check if this looks like a table (has scenarioData.type === 'table' or name includes 'desk')
|
||||
const isTable = (obj.scenarioData && obj.scenarioData.type === 'table') ||
|
||||
(obj.name && obj.name.toLowerCase().includes('desk'));
|
||||
@@ -536,6 +536,7 @@ export function setupNPCTableCollisions(scene, npcSprite, roomId) {
|
||||
if (isTable) {
|
||||
game.physics.add.collider(npcSprite, obj);
|
||||
tablesAdded++;
|
||||
console.log(`✅ Added NPC collision with table: ${obj.name}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user