I am trying to attach a GameObject B to another GameObject A after they collide.
Box Colliders and Rigidbodies are attached to both Objects. Following code enables the Object Merging:
private void OnCollisionEnter(Collision collision)
{
collision.gameObject.transform.SetParent(transform,true);
}
Otherwise no other script affects the objects
The Object B will be parented to Object A as expected. But right after the collision the Mesh Renderer and the Box Collider are no longer on top of each other. In order to obtain a better idea of the situation I have included pictures before the collision, while the collision and after the collision.
I also noticed that a lower collision force also leads to a lower shift. Do you have any idea how the Mesh Renderer and Box Collider can still lie on top of each other, after the collision?
Thank you!