How to build a transform tree from script?

Hi Guys,

I am loading models at runtime that are in the wrong coordinate system (Z-up.) I really dont want to do my whole app in this coordinate system. A negative 90 degree rotation around X fixes the problem, but then its positional coordinates are in its local z-upcoordinate system. :frowning:

What I wanted to do was to attach the model to a parent node that is still in the apps coordinate system The following code however is not working. The parent transform seems to have no effect whatsoever.

What am I doing wrong?

			tile = new GameObject();
			// need to rotate coordinate system
			tile.transform.localPosition = new Vector3(loc.x*10,0,loc.y*10);
			GameObject tileGeometry = 	(GameObject)Instantiate(prefab,
                                    new Vector3(0,0,0),Quaternion.Euler(-90,0,0));
			tileGeometry.transform.parent=tile.transform;

not certain if this is your problem, but pretty sure when you set the parent in the last line, it updates LocalPosition of the child object so that it does not move. You position the child at 0,0,0 before you bind it - so if the parent was at 10,10,10, it would change the child’s local to -10,-10,-10 so that it doesn’t actually move. This would not prevent it from moving with the parent from there on, assuming the parent moves at all - guessing it doesn’t since it’s a tile.

If this is the problem, you just need to set localPosition of the tileGeometry back to 0,0,0 after setting it’s parent. Alternately, use the same position to initialize tileGeometry you do for Tile, so they’re aligned before you parent them.