Should I reinstall unity or am I doing this very simple script Vector thing wrong?

I have an Imported mesh, cylinder and 3 capsules. the last 4 items have configurable joints, and make up a rope I’m going to use for a grapple hook The last capsule is the object the script is on. . I need to Instantiate more hooks as the player holds down a button and the rope gets longer. To do that, I’m going to instantiate new capsules, giving the impression of longer rope. For now it just comes out right away, for easier testing purposes.

However when I instantiate it, it goes to a crazy far away spot, and I have no idea why. It happened with another object in a similar way last post I put on here and no one on here could figure out why.

Basically I want to instantiate it to to the GameObject the script is on’s position, with a bit more on the y axis, but it’s in a completely far off spot. We’re talking nearly around as far out as the environment goes. Why isn’t the Vectior3 “Gop” being read as the gameObject’s position?

if TL;DR, why is the Vector Gop not containing the same coordinates as my gameObject? Something similar happens with transform.Up as well.

 HingeJoint hingejoint;
    public GameObject oneChain;
    public GameObject onechainclone;
    public Rigidbody OneRigid;
    public Rigidbody clonerb;
    ConfigurableJoint lol;
    public float newJ;






    // Use this for initialization
    void Start () {
    
        newJ = 1;
        hingejoint = gameObject.GetComponent<HingeJoint>();

    }
    // Update is called once per frame
    void Update()
    {
        newJ = newJ + 1;
        if (newJ == 15)
        {
            Vector3 Gop = new Vector3(gameObject.transform.localPosition.x, gameObject.transform.localPosition.y, gameObject.transform.localPosition.z);
            Vector3 lulz = new Vector3(hingejoint.anchor.x, hingejoint.anchor.y, hingejoint.anchor.z);
            onechainclone = Instantiate(oneChain, Gop, transform.rotation) as GameObject;
            clonerb = onechainclone.GetComponent<Rigidbody>();
            onechainclone.transform.localScale = new Vector3(5, 15, 5);

        

            hingejoint.connectedBody = clonerb;
            hingejoint.autoConfigureConnectedAnchor = true;
        
        

        }
    }
}

does the GameObject this script is on have a parent? youre using localPosition for Gop instead of position

Yes, it does. The parent is the capsule behind it in the rope.

try

 Vector3 Gop = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);

it’s no longer far away but now I need it Instantiated a little further down it’s local Y axis (the object is already rotated. I don’t need it to go upward, and it will move as the game continues)

ok guys thanks. I solved the issue for this one.

EDIT: I’d really like it if I could get my next, similar problem solved. I posted a link to below the script that you helped me fix.

    // Update is called once per frame
    void Update()
    {
        newJ = newJ + 1;
        if (newJ == 15)
        {
            Vector3 Gop = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
            onechainclone = Instantiate(oneChain, Gop [B]+ transform.up * 20[/B], transform.rotation) as GameObject;
            clonerb = onechainclone.GetComponent<Rigidbody>();
            onechainclone.transform.localScale = new Vector3(5, 15, 5);

    

            hingejoint.connectedBody = clonerb;
            hingejoint.autoConfigureConnectedAnchor = true;
    
    

        }
    }

now if only I could get an answer on my other topic. It’s a similar case of a Vector3 not working quite right. I didn’t use localposition that time.

The vector3 that messes up in that in one is Gos[1]. It’s supposed to be the second-closest gos in an array. It’s right at the bottom. It’s all in the last Method down there.