Transform an objects position to the exact position of another object

I’m trying to figure out how I’d make it so that… when the collider is… triggered and the left mouse button is released, the object stays in the position of the object it collided with…

Also… would I have to make it a child of the object it collided with ?

something along…

void OnTriggerEnter(Collider other)
    {
        obj1.transform.position = obj2.transform.position;
    }

??

I guess the reference way to do this is probably:

  • parent the second object to the first
  • set the (second object) transform.localPosition = Vector3.zero
  • set the transform.localRotation = Quaternion.identity
  • set the transform.localScale = Vector3.one
  • unparent the second object

I’m sorry but… if I have a Cube1 and a Cube2… and I want to move the Cube2 to Cube1…

-Cube1 is the parent, Cube2 is the child

how would I reference the second object here:
?? transform.localPosition = Vector3.zero

Try this (I just typed it, didn’t try to compile it):

 Cube2.transform.SetParent( Cube1.transform);
 Cube2.transform.localPosition = Vector3.zero;
 Cube2.transform.localRotation = Quaternion.Identity;
 Cube2.transform.localScale = Vector3.one;
 Cube2.transform.SetParent(null);

well… the Cube1 that’s the actual trigger “does not exist in the current context” …

I don’t know how to reference an object that doesn’t have this script “attached”

if you know what I mean?

I also just put “gameObject” instead of “Cube2” because the script is attached to it

    void OnTriggerEnter(Collider other)
    {
        gameObject.transform.SetParent(Trigger.transform);
        gameObject.transform.localPosition = Vector3.zero;
        gameObject.transform.localRotation = Quaternion.identity;
        gameObject.transform.localScale = Vector3.one;
        gameObject.transform.SetParent(null);

        Rigidbody myRB = GetComponent<Rigidbody>();
        myRB.isKinematic = true;
    }
    void OnTriggerExit(Collider other)
    {
        Rigidbody myRB = GetComponent<Rigidbody>();
        myRB.isKinematic = false;
    }
}

this is the current script (without the dragging stuff around part that has nothing to do with the colliders)

“Trigger” is the actual name of the object in Unity … not Cube1 …

and the script is attached to Cube2 …

I can’t figure it out … sorry :confused:

Dig into the “other” object… somewhere in there is a reference to the “other” gameobject!