Hi,
I’m creating a game with procedural generated terrain, already have 5 platforms/grounds which are moving in some conditions.The problem is that when I move platform (children of this platform don’t move - and even it’s super hard to move them correctly using manual cordinates (Transform cords dont match with parent cors).
How I can make work this? I want to make children (trees) to follow parent (platform).

Post the code that creates them and sets their positions.
Ok, I will post short part of code. There is too much code to publish it all, and it is separated in few different files.
Moving platform in Z position. That works good.
Vector3 newLocalPosition = new Vector3 (Terrain_1.transform.position.x, Terrain_1.transform.position.y, (terrainNewPos + (changeTerrainCount * terrainLength)));
Terrain_1.transform.localPosition = newLocalPosition;
Mesh_1.ClearMeshFromObjects();
Mesh_1.CreateShape(changeTerrainCount, newLocalPosition);
ClearMeshFromObjects delete all object from TreesParent, to create them again randomized in CreateShape.
I generate new objects in treesParent and then move treesParent to platform position but this is the thing that doesn’t work.
CreateShape (short):
ObjectGenerator.generateObject(tree_1, treeParent, new Vector3(x, y, z));
// THAT DOESNT WORK - it set position not releated with parent
treeParent.transform.localPosition = transform.localPosition;
// I set this position in loop so treesParent should go with platforms
treeParent.transform.position = new Vector3(treeParent.transform.position.x, treeParent.transform.position.y - ((generatorNumber * 52f) - 52f), treeParent.transform.position.z + 300f * changeTerrainCount);
treeParent.transform.Rotate(10, 0, 0, Space.Self);
Line 2 of that first block looks suspicious - you’re setting local position but you’re using Terrain_1’s world position.
@StarManta Global position and local is something new for ne. I thought that there is only one position.
So how I can be sure, and able to use position of one object and set different object to this same position?
Right now I have:
generated platform (which is parent of treesParent)
treesParent (contains GameObjects of tree)
Platform
How I can set treesParent position to same as Platform position?
Tried inside platform GameObject:
treeParent.transform.localPosition = transform.position;
treeParent.transform.localPosition = transform.localPosition;
treeParent.transform.position= transform.position;
etc.
If you want them to be in the same place no matter what the hierarchy says, use line 4. But, if you later move the parent of either of them, then its children move with it.
(Note that the numbers you see in the inspector are always local - relative to the parent)
1 Like