- Home /
Comparing the position of two children objects
So, I'm working on a VR project where I have a character model that goes through several dance poses to teach the player a dance. I want to check that the player is following the character accurately and that's where I'm having trouble.
Right now, I am trying to use the character's local left and right hand positions and compare them to the player's left and right hand controller's local positions. This however is not working as the local position on the character's left and right hands don't change despite the pose changing.
Maybe I am misunderstanding how positions work on transforms, but I wasnt sure how to check the positions globally as hands for both character and player are tied to separate parent objects and exist in different locations.
I've hit a bit of a wall so any ideas on how to approach this checking is greatly appreciated.
youre probaby have a complex hierachy, maybe some like
body-> torso-> left arm -> left elbow -> hand
body-> torso-> right arm ->right elbow -> hand
so you simply cant use localposition (its from left elbow), to get the relative position from main body gamepobject, do some
//transforms of each character's hands
Transform rightHand;
Transform leftHand;
//main parent body
Transform body = leftHand.root;
//positions relative the main parent
Vector3 lHRelativepos = root.InverseTransformPoint ( leftHand.position);
Vector3 rHRelativepos = root.InverseTransformPoint (rightHand.position);
also, you probably know it, but compare a $$anonymous$$imal distance between hand transform and controller transform, due to floating point imprecissions Vector3 =
Vector3 never will be true
@DCordoba alright I'll try getting it that way, thank you. Could you explain what the inverse transform point is doing and why it's different than local position?
hum, probably I didnt explain me very well, lets see.
InverseTransformPoint () is the "local position" relative to the transform that are called
so, if the transform of you call is the parent of the objetive, will be the same of the objetive.localPosition
in code, write
Transform parent = objetive.parent;
Vector3 localpos = parent.InverseTransformPoint( objetive.position);
is the same to write
Vector3 localpos = objetive.localPosition;
but I call it from the root parent
this is some like "the local position of the hand, seen from the main body parent"
if you just call localPosition
, this is seen from the inmediate parent, on my hierachy example is "left elbow"
Okay great, I understand how it works now. Thank you for explaining that. I tried out that code and the positions are different now :) I still have to test it with VR equipment but don't have access to that right now, but I reckon that did the trick!