Hi guys,
Iv’e just encountered a very weird problem.
(BY CODE) I’m instantiating new game object, then adding a sprite renderer component and attaching a sprite object, and only after the sprite is fully loaded, I add a PolygonCollider2D, to fit the sprite iv’e just added.
That works fine on the editor, but when I run it on an iOS device, the colliders seem to be offset.
here is a screenshot to demonstrate the results on both platforms - Unity Editor and iOS Device:
look at the cat object.
in Unity editor, I can drag it to the edge of the screen with no gap.
the collider perfectly matches the sprite.
in iOS device, the picture shows you me, trying to drag the cat object as close as possible to the screen edge. for some reason, the feeling is that
the collider is OFFSET, so it can’t be dragged to the screen’s edge.
Here’s the code that adds the sprite and collider:
currentPiece = new GameObject();
currentPiece.transform.position = PieceDropVector();
currentPiece.AddComponent<SpriteRenderer>();
currentPiece.AddComponent<Rigidbody2D>();
currentPiece.AddComponent<PieceBehavior>();
currentPiece.GetComponent<SpriteRenderer>().sprite = physicalPieceData.spriteOBJ;
currentPiece.GetComponent<SpriteRenderer>().sortingOrder = 3;
currentPiece.GetComponent<Rigidbody2D>().interpolation = RigidbodyInterpolation2D.Interpolate;
currentPiece.GetComponent<Rigidbody2D>().collisionDetectionMode = CollisionDetectionMode2D.Continuous;
currentPiece.AddComponent<PolygonCollider2D>();
currentPiece.GetComponent<PolygonCollider2D>().sharedMaterial = pieceMaterial;
does anyone have a clue about what went wrong?
Note that I didn’t change anything! right after building from unity I built the project on xCode.
Please give me an idea ho to solve this. Thanks!