I’m working in VR and have an object representing a key to a door. It has one child called keyTip. I have a collider in the keyhole called keySlot.
Whenever the keyTip is moved within the keySlot collider, I would like to snap the position of the key so that the center of the keyTip child object lines up with the center of the keySlot object.
(I know I could position the keySlot where I want the center of the key to end up, but I want to account for various sized keys)
This moves the center of the key to the center of the slot, which is not what I want:
key.transform.position = keySlot.transform.position
This moves the keyTip child object to the center of the slot without moving the parent, which is not what I want:
keyTip.transform.position = keySlot.transform.position
Do I manually need to calculate the offset of the keyTip within the key object and offset the final position of the key by that amount?