Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

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.

share|improve this answer
    
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
add comment

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

share|improve this answer
    
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
add comment
up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.