SuperTiled2Unity icon indicating copy to clipboard operation
SuperTiled2Unity copied to clipboard

Game Objects are being placed in wrong positions.

Open cheex0r opened this issue 3 years ago • 1 comments

I have a map with Objects, some of which are undergoing prefab replacement. Bot the non-replace and replaced objects are not being placed in alignment with the tiles. The replaced objects are all being shifted by (0.16, 0.48) (32 ppu). The non-replaced objects are being shift by about (0, 0.36).

The prefabs being added to the scene via replace have coordinates (0,0,0) so I don't think their offsets are stemming from a prefab setting. All of the coordinates in Unity seem to translate to the coordinates in tiled, so I think it has to do with my Unity settings.

Replaced-Objects

Non-Replaced-Objects

cheex0r avatar Sep 05 '22 04:09 cheex0r

I know it's old, but: Tiled use as Pivot the LeftBottom. If u use in SpriteRender images with bottomLeft pivot works. But if u have set different pivot, or custom one...byebye. I've create a script with private bool moveCenterToPivot = false;

public bool MoveCenterToPivot
{ get => moveCenterToPivot; 
    set 
    {
        moveCenterToPivot = value; 
        if (value)
        {   
            SpriteRenderer spriteRenderer = GetComponentInChildren<SpriteRenderer>();
            Vector3 pivotInUnits = spriteRenderer.sprite.pivot / spriteRenderer.sprite.pixelsPerUnit;
            this.gameObject.transform.position = this.gameObject.transform.position + pivotInUnits;
        }
    }
}

and i add to every Object. In tiled I put a boolean MoveCenterToPivot (true) for every object that need to move.

willyx78 avatar Nov 28 '23 17:11 willyx78