Make object Rotate on Local axis in same time to another with parents.

Hello everybody :slight_smile:

I’m doing a VR game and I have some trouble with positionning my arm in the same rotation to the hand :confused:

Here a little video of what i’m talking:

My root parent object it’s my player, inside it I have my left controller object who’s moving(with tracking ect…). inside it I have the Handmodel 3D with offset to match with real hand .

Inside my hand 3D model I have the arm object with he’s center to the pivot point for the wrist. And inside this I have the 3D model of the arm… (A lot of "inside I know ^^)

I have a script attach to arm gameobject to smooth look at a elbow object with :

 transform.rotation = Quaternion.Slerp(transform.rotation, targetrotation, speed * Time.deltaTime)

So ther’s someone can explain me how to achieve that ? :confused:

I can’t set the local rotation to the handmodel to the armmodel because they have both (0,0,0) in local rotation :confused:

In other word, I would like to rotate a object on a specific Z axis coresponding to my hand model rotation in Z too but here, convert from worldspace rotation ?

If someone can help me i’ll really appreciate :smile: !!

Have a good day :)!

I think you have to approach it like this:

You need to make an arm bone transform look in the direction of the UP of the hand (for instance, considering the thumb is UP), and when you do that LookAt() you want to give it the direction of the elbow joint as the second argument, which is the “up” argument.

The mental image I have is you are lying on your back on your forearm, and you are looking up in the direction of the thumb, and your head’s “up” is back towards the elbow, something like this:

Vector3 ThumbPointingDirection = ... however you pull this off your hand

Vector3 VectorFromHandToElbow = HandPosition - ElbowPosition;

// ArmLookBone is a Transform
ArmLookBone.LookAt( ArmLookBone.position + ThumbPointingDirection, VectorFromHandToElbow);

After that you can parent the real visible arm geometry however you like beneath the arm bone.

Considering the thumb can tilt forward and back, you might need to first zero out the fore-aft rotation of the thumb, perhaps by recreating the rotation using purely the wrist Z-axis rotation, not the wrist rocking, something like:

float wristRotation = WristTransform.localRotation.eulerAngles.z;

Vector3 ThumbPointingDirection = Quaternion.Euler( 0, 0, wristRotation) * Vector3.up;

Here’s my best visual: