Quick answer: flipX is a renderer-only property. Flip the BoxCollider2D’s offset.x in the same step: col.offset = new Vector2(flipped ? -baseOffset : baseOffset, col.offset.y).
A character has an asymmetric collider that extends to the right (sword hitbox). Setting spriteRenderer.flipX = true mirrors the visual, but the collider still extends right when the character faces left. Hit detection is wrong.
Renderer vs Physics Separation
flipX only flips the SpriteRenderer’s draw output. Physics2D doesn’t see this. The collider lives on the same GameObject (or a child) and uses its own offset/transform. Coupling is your responsibility.
Fix 1: Flip Collider Offset
private const float COLLIDER_BASE_X = 0.5f;
[SerializeField] BoxCollider2D _collider;
[SerializeField] SpriteRenderer _renderer;
public void SetFacing(bool facingLeft) {
_renderer.flipX = facingLeft;
_collider.offset = new Vector2(facingLeft ? -COLLIDER_BASE_X : COLLIDER_BASE_X, _collider.offset.y);
}
Renderer flip and collider offset toggled together. Hit detection follows facing direction.
Fix 2: Symmetric Colliders
For most body colliders, keep them symmetric around origin (offset.x = 0). Only flip the visual; physics handles itself. Reserve offset-flipping for asymmetric attack hitboxes.
Fix 3: Negative Scale
transform.localScale = new Vector3(facingLeft ? -1 : 1, 1, 1);
Affects both visual and collider. Works but has side effects: child rotations may flip oddly, particle systems may emit in mirrored directions, and some shaders treat negative scale as a degenerate transform. Test thoroughly.
Verifying
Face the character left and right. The asymmetric collider should always extend in the facing direction. Use gizmos to confirm collider position matches the rendered sword.
“flipX flips visuals only. Flip offsets together if your collider isn’t symmetric.”
Wrap facing changes in a single SetFacing helper so visual + collider always update together.