Obi Official Forum
Attaching a child gameobject to a gameobject pinned to a rope - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Attaching a child gameobject to a gameobject pinned to a rope (/thread-1169.html)



Attaching a child gameobject to a gameobject pinned to a rope - nigelkennington - 09-05-2019

Hi,

I have a crane with a hook pinned to two obiropes. That's working fine, but I'm having a real problem when the crane hook "picks up" a different game object. If the game starts with the hook parented to a gameobject, everything is fine:

[Image: SA7eNMC.gif]

but if I use the script to parent it while the game is running it behaves very oddly:

[Image: qWBEDmU.gif]

Any idea what I am doing wrong?


RE: Attaching a child gameobject to a gameobject pinned to a rope - josemendez - 09-05-2019

(09-05-2019, 03:48 PM)nigelkennington Wrote: Hi,

I have a crane with a hook pinned to two obiropes. That's working fine, but I'm having a real problem when the crane hook "picks up" a different game object. If the game starts with the hook parented to a gameobject, everything is fine:

[Image: SA7eNMC.gif]

but if I use the script to parent it while the game is running it behaves very oddly:

[Image: qWBEDmU.gif]

Any idea what I am doing wrong?

Hi there,

Tested in the Crane sample scene, but can't reproduce anything strange. Programmatically parenting to a pinned object works just fine for me. Can you share the code you're using to parent the second object?


RE: Attaching a child gameobject to a gameobject pinned to a rope - nigelkennington - 09-05-2019

(09-05-2019, 04:02 PM)josemendez Wrote: Hi there,

Tested in the Crane sample scene, but can't reproduce anything strange. Programmatically parenting to a pinned object works just fine for me. Can you share the code you're using to parent the second object?

Thanks Jose,

Here's the code:

Code:
   private void OnTriggerStay(Collider other)
   {
       print("Got a collision with " + other.gameObject.name);
       if (other.gameObject.tag == "LiftPoint")
       {
           if (Vector3.Distance(transform.position, other.gameObject.transform.position) < connectDistance)
           {
               print("Got one! " + other.gameObject.name + " is touching " + this);
               if (remainingConnectTime > 0)
               {
                   // Countdown remaining time
                   remainingConnectTime -= Time.deltaTime;
                   print ("Counting down! " + remainingConnectTime);
               }
               else
               {
                   print("Connecting!");
                   // Connect, disable attachpoint, reset timer
                   remainingConnectTime = connectTime;
                   other.gameObject.transform.parent.parent = this.transform.Find("LoadAnchor");
                   other.gameObject.SetActive(false);
               }
           }
           else
           {
               print("Resetting to " + connectTime + " :-(");
               remainingConnectTime = connectTime;
           }
       }
   }

All it's doing is counting down 3 seconds if the hook is inside the attachpoint, then setting the attachpoint's parent's parent to be the anchor of the hook and disabling the attachpoint.

(09-05-2019, 04:20 PM)nigelkennington Wrote: Thanks Jose,

Here's the code:

...

All it's doing is counting down 3 seconds if the hook is inside the attachpoint, then setting the attachpoint's parent's parent to be the anchor of the hook and disabling the attachpoint.

I've taken the rigidbody off the child object and that seems to have fixed it.

Thanks for trying to help though!


RE: Attaching a child gameobject to a gameobject pinned to a rope - josemendez - 09-05-2019

(09-05-2019, 04:20 PM)nigelkennington Wrote: I've taken the rigidbody off the child object and that seems to have fixed it.

Glad you figured it out!

Parenting a rigidbody to another rigidbody does not make sense, regardless of it being pinned to a rope or not:

https://answers.unity.com/questions/62497/-you-should-never-have-a-parent-and-child-rigidbod.html

In newer Unity versions it *can* be done, but gravity will still affect the child rigidbody in world space, making it pretty much useless. Establishing spatial relationships between rigidbodies should always be done via joints.