Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
In game parenting of Obi Particle Attachment
#11
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;
                }
            }
        }
    }



    }
Reply


Messages In This Thread
RE: In game parenting of Obi Particle Attachment - by Holty - 07-06-2023, 08:43 AM