0
\$\begingroup\$

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.

enter image description here

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.

enter image description here

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?

\$\endgroup\$
0

3 Answers 3

0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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? \$\endgroup\$
    – Esa
    Jul 23, 2012 at 6:30
0
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – Esa
    Jul 23, 2012 at 6:07
0
\$\begingroup\$

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

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .