Implement the following plan: Fix NPCInteractionSystem to Support ConvexCollider Context…
- User
Implement the following plan:
Fix NPCInteractionSystem to Support ConvexCollider
Context
The Blender pipeline replaces
BoxColliderwithConvexCollideron entities that have a collider child mesh (*-collider). The Player entity goes through this path, so it ends up with aConvexColliderinstead of aBoxCollider. However,NPCInteractionSystemhardcodesBoxColliderin its ECS queries — when the player has aConvexCollider, it silently drops out of the query and all NPC dialogue interaction stops working.The collision system itself does support cross-type interactions (Box vs Convex) — the issue is entirely in
NPCInteractionSystemdoing its own proximity check with hardcodedBoxColliderqueries.Fix
Single file change:
MonoDreams.Examples/System/NPCInteractionSystem.csFollow the established pattern from
TransformCollisionDetectionSystem: useColliderTagin ECS queries and resolve the AABB at runtime based on the actual collider type.1. Player query (line 33):
BoxCollider→ColliderTagcsharp// Before .With<BoxCollider>() // After .With<ColliderTag>()2. Zone query (line 40):
BoxCollider→ColliderTagSame change for consistency and future-proofing (zones are currently always BoxCollider but this makes the code resilient).
3. Player AABB resolution (lines 69-71): handle both collider types
csharp// Before var playerCollider = playerEntity.Get<BoxCollider>(); var playerRect = CollisionRect.FromBounds(playerCollider.Bounds, playerTransform.WorldPosition); // After var playerRect = playerEntity.Has<BoxCollider>() ? CollisionRect.FromBounds(playerEntity.Get<BoxCollider>().Bounds, playerTransform.WorldPosition) : playerEntity.Get<ConvexCollider>().BroadPhaseAABB;ConvexCollider.BroadPhaseAABBis already aCollisionRectin world space — no position offset needed. Assistant
Let me read the file first, then apply the changes.
Assistant
Now I'll apply all four changes.
Assistant
All four changes applied. Let me build to verify.
Assistant
Build succeeded with 0 errors. Now let me run the tests.
Assistant
All 26 tests pass. Here's a summary of the changes made to
MonoDreams.Examples/System/NPCInteractionSystem.cs:-
ECS queries (lines 33, 40): Changed
.With<BoxCollider>()to.With<ColliderTag>()so the player and zone queries match entities regardless of collider type. -
Player AABB resolution (line 70): Instead of hardcoding
BoxCollider, now checks at runtime withHas<BoxCollider>()— usesCollisionRect.FromBoundsfor box colliders, orConvexCollider.BroadPhaseAABBdirectly for convex colliders. -
Zone AABB resolution (line 79): Same runtime dispatch pattern for dialogue zones.
-