Implement the following plan: Fix ConvexCollider misalignment with sprites from Blender…
- User
Implement the following plan:
Fix ConvexCollider misalignment with sprites from Blender pipeline
Context
When the collider debug overlay is enabled, the store's ConvexCollider (red outline) appears tiny and offset from the actual store sprite. The root cause is that
ApplyColliderChilddoesn't account for the parent sprite's origin offset when building ConvexCollider model vertices, whileProcessCollectionscorrectly does this for BoxColliders.How it works today
BoxCollider path (
ProcessCollections, line 475-509): Computes a visual offset from the parent'sOriginOffsetand bakes it into the collider bounds:codeleft = -size.X * originOffsetX top = -size.Y * (1 - originOffsetY)This compensates for SpriteBatch.Draw shifting the sprite visual from the entity position.
ConvexCollider path (
ApplyColliderChild, line 574-651): Takes collider child vertices exported byobj.matrix_local @ v.co(parent-local coordinates relative to the Blender origin) and uses them directly as model vertices — without the visual offset that SpriteBatch.Draw applies to the sprite.Result: The sprite shifts by
(-origin * scale)from entity position, but the ConvexCollider stays at the raw Blender-origin-relative coordinates. For the store (originOffset 1.15, 1.10 — origin is outside the bounding box), this produces a dramatic misalignment.Affected entities
All entities with
-colliderchildren whose parent has a non-centered origin:- store: originOffset (1.1526, 1.0991) — severe misalignment
- Boldo: originOffset (0.4675, 0.5433) — slight
- Pete: originOffset (0.4774, 0.5033) — slight
- elephant-kid: originOffset (0.5, 0.5) — unaffected (centered)
Fix
MonoDreams/System/Level/BlenderLevelParserSystem.cs—ApplyColliderChild(~line 588)After building
modelVerticesfrom the exported data and before the degenerate-shape guard, offset all vertices by the parent sprite's visual shift:csharp Assistant
Let me read the relevant section of the file to find the exact insertion point.
Assistant
Now I'll insert the origin offset fix after line 593 (where
modelVerticesarray is built) and before line 595 (the degenerate-shape guard).Assistant
Now let me build and run the tests to verify.
Assistant
Build succeeds with 0 errors and all 26 tests pass.
The fix adds the sprite origin offset to ConvexCollider model vertices in
ApplyColliderChild(line ~595 ofBlenderLevelParserSystem.cs). This matches whatProcessCollectionsalready does for BoxColliders — compensating for theposition - origin * scaleshift thatSpriteBatch.Drawapplies when rendering sprites.To visually verify: run the game, press F1, enable "Collider Shapes", and confirm the store's red ConvexCollider outline now aligns with the sprite.
- User
Now it's worse I think. Need further adjustments maybe?
- User
[Image: image/png]
Assistant
I see — the colliders are now shifted even further away. Let me dig deeper into the coordinate systems to understand what's actually happening.
Assistant
Let me explore the full picture — how colliders are rendered in the debug system, how
ProcessCollectionshandles BoxColliders, and how the Blender exporter produces vertex coordinates.Assistant
Good data. Now I need to understand one critical missing piece — how
UpdateWorldVerticestransforms model vertices to world space. Let me check that and the actual store dimensions.Assistant
Now I understand the critical piece —
UpdateWorldVerticesappliesTransform.Scalewhich is(1,1)since Blender scale is baked intoSpriteInfo.Sizebut NOT into the collider vertices. Let me verify this theory and check how to access parent scale data.Assistant
Now I have the complete picture. The original plan's theory about origin offset was wrong. The actual bug is that parent Blender scale isn't applied to collider child vertices. Let me verify one more detail and then write the corrected plan.
Assistant
Good. I now have the full picture. Let me write the corrected plan.
- User
[Request interrupted by user for tool use]