Need localPosition.x in world units.

Hey guys, quick simple question (and I’m sure there’s a simple solution but I can’t quite get my brain around it, despite hounding the script reference and UA…)

Here’s some js psuedocode:

var child : Transform;
var parent : Transform;

child.parent = parent;
child.localPosition = Vector3(2, 3, 4);
parent.localScale = Vector3(0.5, 0.5, 0.5);

I need some way to get child’s local position, but in world coordinates. In this case, child.localPosition.x will return 2. What I need is a function that would return 1 (the ‘actual distance’ the object is displaced along the x axis from its parent.)

Oh yeah, I need this to work no matter how deep the ancestry of the child.

Thanks fellas!

(Semi-related fiery explodey goodness for your trouble: woohoo!)

Answered my own question. LossyScale to the rescue! Just multiplied the object’s localPosition by its parent’s lossyScale to get the conversion.

You can use this to convert local rotation to world rotation.