Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

How is localScale adjusted when re-parenting transforms?

$
0
0
I am trying to mimic Unity's behaviour where it concerns transform parenting, and I'm stumbling on something I can't explain. Say I have 2 GameObjects. They both are without a parent. One is named "Root", the other "Child", because that is what the hierarchy will end up like. Both are already translated, rotated and Root is non-uniformly scaled. ![Root][1] ![Child][2] Now, at run-time, I parent Child to Root. When this happens, Unity will preserve the global position and orientation of the Child, and in the documentation it also states it preserves scale. It does so by modifying the local transform values/matrix in such a way that its global transform is preserved. Or, that is the assumption. What this new "local" matrix would need to be is localTransformMatrix = parentTransform.worldToLocalMatrix * childTransform.localToWorldMatrix; `localRotation` and `localPosition` would be easy enough to derive. And the `localScale` would seem to be found in the length of the colums of the localTransformMatrix (or its 3x3 rotation part). But ... that doesn't stroke with what Unity actually does. The new localScale I actually get is (0.6140807, 0.8078736, 0.4113787) And that's where my confusion starts. If you parent objects, and inspect the localToWorldMatrix of the Child object, you'll notice that in fact it is modified. Global position and orientation are preserved, but there is an effect on the scale (and subsequently the localScale) that I can't seem to match when computing by hand. So what is going on here? What is Unity actually doing when parenting, and how can I compute the correct values (matching what Unity gives) if I were to compute it by hand? [1]: /storage/temp/76436-root.png [2]: /storage/temp/76437-child.png

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>