position transformations

I have a function that outputs the positions of several points that I use to connect lines to.

Each line is its own gameobject, initially the calculation of the positions works great. But I parented all the lines together so they could be deleted all at once when they are not needed.

What happens is that the lines all appear in the correct position initially. But once the parent moves around the position of the lines gets messed up.

Since it works fine before I parented I originally thought that I needed to transform from world to local, I also tried local to world.

If Im not being clear let me try this. Before parenting, the point coordinates are fine. After parenting the point coordinates are not fine.

What do you want to happen when the parent moves? Note that the values shown in the inspector are local - I.e. relative to the parent.

–

1 Answer

1

I’ve seen that. What I do is save off the localPosition, localRotation, and localScale of the child, then parent, then restore those things.

That will move the children. The normal behaviour is that setting the parent of a transform will preserve the world position of the child. Which you want depends on what you are doing.

–