Player pick an object, lets say a key, then he moves the key close to the key hole and as the key gets close to the keyhole, it aligns with it and eventually snaps in place.
Once the player picks up the object and moves it close enough to the keyhole, start interpolating from the key rotation to the keyhole rotation, or the desired end rotation (perhaps -forward axis of the keyhole or something).
That interpolation can either be all at once over time like an animation, or based on the remaining distance.
I imagine the easiest way would be to use a physics trigger around the keyhole, and when the key touches it, it automatically aligns and snaps into place. That way it always looks good regardless of player intervention or other shenanigans that could affect a distance-based approach, and you can use your trigger radius as the snap-distance.
Thanks, that is the first idea I got when thinking about it, however I want to do more advanced movement, for example the player may move the key around the keyhole and the tip of the key should still point to the hole.
Is there a way to use joints? Im very new to joints so Im trying to figure that.
Another use case is for example a bow in VR, where the player grabs the arrow and places it into the arrow socket, he can still move the back of the arrow and it will rotate according an anchor point.
Im trying to make a test scene of a bar and t anchor points, the bar will be always aligned to the anchor points and by moving the anchors the bar will move aligning to it.
That is definitely doable. You may want to look into how the LookRotation and LookAt functions work, but it’s relatively simple to get an object to point one of its axes at another object.