- Home /
Child objects with different scales move differently?
Let's say I have two identical cubes--each of which have a scaled down cube as a child. On one parent cube I place a script that moves the cube 10 units up. On the other parent cube's child I place the same script. On the first cube, both of the cubes move up 10 units, when I hit play. But on the second cube, when I hit play, only the child moves, right? Right. Except the second cube's child moves much more than 10 units up. Looks more like it's related to the ratio of itself to it's parent's scale. At the same time, it's still saying it's moving only 10 units. CONFUSIONTOWN.
What gives? Is this a feature? If it is a feature, what would it be useful for? How do I stop this scaling and moving effect from happening? Why would I not want to know exactly how many units it was actually moving? I was using empty parented game objects as a means to organize things in the hierarchy, but now I'm just scared.
Answer by aldonaletto · Nov 12, 2011 at 04:32 PM
How are you moving these cubes? If you modify localPosition, yes, the childed cube will be moved by displacement * parent scale. When you child an object, its transform.localScale (transform.scale doesn't exist) is divided by the parents scale to keep the relative proportions - if you scale the parent, the child will be scaled proportionally.
You can move the child using transform.Translate, or even transform.position - they're not affected by the parent scale.
AH! Excellent stuff to know. But I am moving it by transform.position...and that's what's causing the effect. I still don't understand why I would ever want not to know the "real" height independent of scale, you know? Seems like it might be useful for some game concepts, but not the majority of them...yeah?
With transform.position? Weird thing: I tested this, and only localPosition took scale into account (as expected): transform.position and transform.Translate ignored the scale, and resulted in the same displacements in different scales.
Hmm...so are we agreed, there is something weird going on here? What do you mean by "the same displacements in different scales"?
gameObject.transform.position.y was what I was using to access it the whole time I've never used localPosition, as I'm not really sure what it needs to be used for.
Answer by sweatyrat · Jun 15, 2012 at 04:05 PM
as to why it is useful, if you have a huge map like a solar system, the vector3 transform cant hold all the precision you need for far away object. but if you make your game a series of layers such as the solar system has sector children and all objects are in some sector then you set the sector objects scale to 1 and the solar system scale to 10000 then sector1 for example is just 1 sun local position unit away but its 10000 away in base units so your player object is at its sectorlocalposition+sunlocalposition*10000 and it keeps a high level of precision at huge distances that would not work otherwise.