I’m working on a 3D puzzle game where I’ve added anchor points to the objects for matching and docking based on their positions. When two pieces are matched, I create a parent node to group them together for movement. Now the issue is that when using the grouped pieces to dock with others, there is a gap at the docking point. Can anyone help me solve this issue?
这样改`
// 获取正方体1的祖物体
Transform ancestorTransform = transform.root;
// 计算正方体1相对于祖物体的本地偏移
Vector3 localPositionOffset = ancestorTransform.InverseTransformPoint(transform.position);
Quaternion localRotationOffset = Quaternion.Inverse(ancestorTransform.rotation) * transform.rotation;
// 计算目标位置和旋转
Quaternion targetGlobalRotation = item.Value.transform.rotation * Quaternion.Inverse(localRotationOffset);
// 设置祖物体的位置和旋转
ancestorTransform.rotation = targetGlobalRotation;
Vector3 targetGlobalPosition = item.Value.transform.position - transform.position;
ancestorTransform.position += targetGlobalPosition;`

