- Home /
How to compare two rotations from children objects
So I'm trying to compare positions and rotations of two hand objects (manipulated by VR) to another avatar's hand objects. The hierarchy of these objects is the same - an empty gameobject holds the avatar, and the avatar has children such as hips, spine, arms, hands, etc. I got the position comparison to work correctly but using inverse transform point and then flipping the z axis since the avatars are facing each other. I cant figure out the rotations however. I've attempted just comparing one hand's rotation to the other avatar's hand rotation, using Quaternion.Angle() but it's not giving the expected results. I'm not too familiar with Quaternions and how to use them, but is there something I need to do like with the position to get the correct comparison results?
Answer by rufopufo · Jun 28, 2019 at 06:21 AM
Hi there,
So, I am not sure what you are looking for.
But there is a property in the transform component that gives you exactly the angles in degrees of your object's rotation:
Vector3 myRotation = transform.eulerAngles;
If you use the property "localEulerAngles" you will get also a Vector3 with the angles of rotation in degrees, but this time, they will be relative to the parent rotation.
I am not a big fan of Quaternions, so I don't like to use them personally... So there is always a way to still use degrees, or make it work with a simpler solution.
Hope it helps.
@rufopufo So how would I use that to compare to angles? For example the right hand of the player and the left hand of the instructor. This is what I tried, but I couldn't seem to get the angles to match despite them visually being in the correct position. The difference that came up was always around 200.
void Check$$anonymous$$ovement() { //called from update ... Vector3 playerRightHandRot = playerRightHand.eulerAngles; Vector3 instructorLeftHandRot = instructorLeftHand.eulerAngles; ... }
void CheckLeftHand() { //called from Check$$anonymous$$ovement ... float angle = Vector3.Distance(playerRightHandRot, instructorLeftHandRot); ... }