Beginner C# developer in Unity, working with Oculus 2. I'm experimenting with Unity XR's hand tracking functions. So far I can grab an object with my hands, scale it, rotate it around, and release. Now I have a parent gameObject "Skeleton" that's formed by all the major bones in the body (separate gameObjects under the hierarchy). I have a cylinder around the skeleton gameObject with Collider set to "Is Trigger." No rigidbody on the cylinder so that my hands can pass through and grab individual bones.
I want to be able to reset the bones I take out of the skeleton form and have them snap back to their rightful (original) positions. I would like them to stay as they are, floating in space, if I release them out in the open air. BUT, if I release them within the collider of the cylinder that surrounds the skeleton form, that's when they snap back.
Also would like to set a reset button that also does this.
I'm using the Unity XR Interaction Toolkit scripts for hand interactions, so not sure what commands they're using and what scripts they're calling.
Thanks!
Summary: So far I can grab an object with my hands, scale it, rotate it around, and release. The object hangs in the air where I released it. I know I need to log variables for start position & rotation, and I think identify the collider on the cylinder gameObject, then call either OnCollisionEnter or OnTriggerEnter? Not sure what to do from there.
Okay, I assume your bones' rigidbody are already on isKinematic (they ignore gravity and other forces). So when they will enter in collision with the collider of the skeleton, a OnTriggerEnter event will be raised in the skeletons scripts (not a collisionEnter because your skeleton's collider is set to "Is Trigger" as you said). You will have to use this event to reset the position of the bone entering. The parameter of the OnTriggerEnter method is the collider entering so with it you'll have access to the specific bone entering.
First to log the position and rotation, I would create a class for bones like 'BoneScript' or 'BoneComponent', store the initial transform values and create a public method that will reset thoses values.
Then in the skeleton Class, you will have to check if the rigibody entering is a bone or not and if so, reset his position. You could create a tag for your bones, use a layerMask or try to get its BoneScript. Here are the 3 methods :
For the reset button, you could call a function like
Then for a button, check the sample of the XR interaction Toolkit, they have a demo scene with buttons, you can juste take one as prefab and find where the function is called to call ResetAllBones