- Home /
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!)
Answer by SergeantBiscuits · Sep 21, 2012 at 03:11 AM
Answered my own question. LossyScale to the rescue! Just multiplied the object's localPosition by its parent's lossyScale to get the conversion.
Answer by Pandiux · Sep 21, 2012 at 01:45 AM
You can use this to convert local rotation to world rotation. http://docs.unity3d.com/Documentation/ScriptReference/Transform.TransformPoint.html
Your answer
Follow this Question
Related Questions
Move object relative to its axis 2 Answers
Local distance movement 0 Answers
Write IEnumerator for Movement 1 Answer
Syncing up two GameObjects' timestep 1 Answer
change instance color based on distance from player 0 Answers