07-06-2023, 08:43 AM
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;
}
}
}
}
}