Disabling a rigidbody

I’m making a game that has a grab and drop mechanic. I managed to write the code to grab the object, but because the object has a rigidbody, I am unable to hold the object and look straight up. Is there a code that disables a component in the gameObject when the gameObject become the child of an object tagged player? Thanks.

Wouldn’t recommend disabling the rigidbody. Try this instead. It turns off gravity and forces, basically.

gameObject.GetComponent<RigidBody>().isKinematic = true;

As for WHEN to apply the change, it seems like your code might be a bit of a mess from your description… when you grab and release it, you should be applying the settings then in that same code.

Assuming you’re changing the parent somewhere in your code, you can do this:

    grabbableObject.transform.SetParent(newParent.transform);
    
    if(newParent.tag == "player")
    {
        RigidBody objectRigidBody = grabbableObject.GetComponent<RigidBody>();
    
        if(objectRigidBody  != null)
        {
            objectRigidBody.enabled = false;
        }
     }