07-06-2023, 11:02 AM
(This post was last modified: 07-06-2023, 11:03 AM by josemendez.)
(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?