transform.parent = otherObject.transform;
should definitely work. there must be some something else moving “otherObject”. maybe another script that needs disabling on contact.
maybe the child still has its own rigidbody component moving it independently after parenting?
try disabling the child’s rigidbody on contact.
or better yet, lock the rigidbody x y z on contact, and disable the child’s gravity.
you only want it to do these things with the new parent.
I want to attach the object1 to object2 when object1 collides with object2 so the object2 stays firm during pushing. Where should I put this two codes above into my code. Could you please show it with a clear explaination?