1
\$\begingroup\$

I am making a factory game and for it I need to set the position of a hologram of a machine so that the end of the hologram's conveyor snaps to the end of the machine next to its conveyor when hovering over the tip of the adjacent machine's conveyor (e.g. if the mouse hovers over the tip of the upper left conveyor in a machine then the hologram snaps to position the tip of the lower right conveyor onto the hovered tip): What should happen, but only happens for some mounts

The issue I am having is that for around half of the mounting points the offset of the hologram is doubled, as seen below: Offset of the hologram is doubled

Here is my code and variables:

        if (Physics2D.OverlapPoint(mouseworld) != null)
        {
            if (Physics2D.OverlapPoint(mouseworld).gameObject.CompareTag("Building"))
            {
                if (building == "Forge")
                {
                    overlap = Physics2D.OverlapPoint(mouseworld).gameObject;
                    holo.transform.position = overlap.transform.position + forgeOffset[System.Array.IndexOf(rotations, Physics2D.OverlapPoint(mouseworld).gameObject.name)];
                }
                Debug.Log("Hit");
            }
            else
            {
                // Lock hologram to mouseworld
                holo.transform.position = mouseworld;
            }
        }
        else
        {
            // Lock hologram to mouseworld
            try { holo.transform.position = mouseworld; }
            catch { Debug.Log("No building selected"); }
        }

Script public variables

rotations is ["DL", "DR", "UL", "UR"]

\$\endgroup\$

0

You must log in to answer this question.

Browse other questions tagged .