# Parent-Child position mathematics

What is the math theory when a child object moves with the parent transform?

I am doing an angle indicator which shows a field of view, which works fantastic when the angle is static. But I cannot get the field of view indicators to play nice with the angle changing. Everytime I change the angle, the indicators are reset to default positions and then the direction indicator and FoV indicators are out of sync.

There is of course a ghetto way of resetting the whole thing when changing the angle, but I'd prefer not to do it that way.

The red circles are the points which are used to draw the FoV lines and they are childed to the white sphere. If the angle is not modified after start they follow the white sphere nicely and show the FoV correctly.

Here is how it looks after trying the dynamic angle changing. The FoV lines should be pointing to the right and the white sphere should be in the middle.

Currently I am changing the red circles' position based on the angle given(transform is the green square in the middle.):

leftAngle.transform.position = transform.position + new Vector3(Mathf.Cos(firstLineRendererAngle * Mathf.Deg2Rad), 0, Mathf.Sin(firstLineRendererAngle * Mathf.Deg2Rad)) * 10;
rightAngle.transform.position = transform.position + new Vector3(Mathf.Cos(secondLineRendererAngle * Mathf.Deg2Rad), 0, Mathf.Sin(secondLineRendererAngle * Mathf.Deg2Rad)) * 10;


How do I add the position of the FoV direction sphere to emulate parent-child relationship with the objects?

I believe the theory you're looking for is Affine Transform

...is a transformation which preserves straight lines (i.e., all points lying on a line initially still lie on a line after transformation) and ratios of distances between points lying on a straight line (e.g., the midpoint of a line segment remains the midpoint after transformation).

And an affine transformation is equivalent to a linear transformation followed by a translation, which I believe is the ghetto method you were talking about?

Anyway, you can find a Unity specific answer about affine transforms here.

• Im afraid I could not grasp the idea of using affine transforms to make the FoV indicators to follow the direction(white ball) properly. How should it be used in this case? – Esa Jul 23 '12 at 6:30

You could use a transform heirarchy, making the transforms of the 2 red balls children of the transform of the white ball.

• Yes, they currently are childed to the direction(white ball). But this does not work when I change the position of the red balls according to the FoV angle. When I change the angle the current code does not take into account the direction and always points up. – Esa Jul 23 '12 at 6:07

Solved this by checking the angle of the EyeDirection(white sphere) and then substracting that amount from the indicator angles.