Obi Official Forum
In game parenting of Obi Particle Attachment - 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: In game parenting of Obi Particle Attachment (/thread-3893.html)

Pages: 1 2


RE: In game parenting of Obi Particle Attachment - Holty - 07-06-2023

Sure here you go:

Code:
public class RopeSnap : MonoBehaviour
{
    private Transform parentPosition;

    private void OnTriggerEnter(Collider other)
    {
        {
            // Check tag of object colliding with
            if (other.CompareTag("RopeEnd"))
            {
                //get current position of the parent object
                parentPosition = this.transform;

                // Get the rigidbody component of the collided object
                Rigidbody childRigidbody = other.GetComponent<Rigidbody>();

                // Check if the rigidbody component exists
                if (childRigidbody != null)
                {
                  
                    //Set position to current position of the parent
                    other.transform.parent = parentPosition;

                    // Set the collided object's rigidbody to kinematic
                    childRigidbody.isKinematic = true;
                }
            }
        }
    }



    }



RE: In game parenting of Obi Particle Attachment - josemendez - 07-06-2023

(07-06-2023, 08:43 AM)Holty Wrote: Sure here you go:

Code:
public class RopeSnap : MonoBehaviour
{
    private Transform parentPosition;

    private void OnTriggerEnter(Collider other)
    {
        {
            // Check tag of object colliding with
            if (other.CompareTag("RopeEnd"))
            {
                //get current position of the parent object
                parentPosition = this.transform;

                // Get the rigidbody component of the collided object
                Rigidbody childRigidbody = other.GetComponent<Rigidbody>();

                // Check if the rigidbody component exists
                if (childRigidbody != null)
                {
                  
                    //Set position to current position of the parent
                    other.transform.parent = parentPosition;

                    // Set the collided object's rigidbody to kinematic
                    childRigidbody.isKinematic = true;
                }
            }
        }
    }



    }

This works just fine for me. Doesn't really make sense for parenting to affect the rope in any way, since they're completely separate systems: ropes apply forces to any rigidbody they're attached to via a dynamic attachment, regardless of what the body's parent transform is, or whether it is kinematic or not (kinematic rigidbodies just ignore any forces applied to them).

Are you doing anything else with regards to the rope, such as using a cursor to change its length, or collision filters to change the way it collides with things around it?




RE: In game parenting of Obi Particle Attachment - Holty - 07-06-2023

Ah ha! Might be the way I set the rope up then. The way I rotated it vertically from it's default horizontal when added to the scene. Maybe the orientation or length setting. I'm away from the project but will re-do the scene with new rope and let you know what happens! Thanks!


RE: In game parenting of Obi Particle Attachment - Holty - 08-06-2023

OK new scene and fresh Obi assets and I'm getting the same thing. Think it's down to how I'm setting up the rope initially. I'm after long thin vertically hanging - non stretchy rope such as climbing rope about 15 to 20 meters in length.

Could you briefly go through the steps you would go through to create this please?


RE: In game parenting of Obi Particle Attachment - josemendez - 08-06-2023

(08-06-2023, 10:37 AM)Holty Wrote: OK new scene and fresh Obi assets and I'm getting the same thing. Think it's down to how I'm setting up the rope initially. I'm after long thin vertically hanging - non stretchy rope such as climbing rope about 15 to 20 meters in length.

Could you briefly go through the steps you would go through to create this please?

Hi,

There's not much that can go wrong while setting this up. The steps are:

1.- Create a new ObiRope object, GameObject->3D Object->Obi->ObiRope.
2.- Assign a blueprint to the rope, I used the "very long cable" included one.
3.- Rotate/translate the rope however you want. It's not necessary to deal with individual control points if you want a simple straight rope.
4.- Add 2 ObiParticleAttachment components to the rope: one static, one dynamic. The static one attaches one end of the rope to the rope's own transform, the dynamic one attaches to a spherical rigidbody.
5.- Create a trigger collider and add your script to it.

I've attached a zipped .unitypackage file with my scene, hope it helps.

let me know if you need further help,

kind regards


RE: In game parenting of Obi Particle Attachment - Holty - 09-06-2023

Thank you for doing that. Having the rope itself as the static particle attachment transform sorted it.