- Home /
Question by
fddefdef · Feb 16, 2015 at 03:54 PM ·
transformchildissuelocalposition
Local position issue
Hi guys,
I have a problem with two simple code lines. I don't know if i'm doing something wrong. Here's the code.
float localX = Mathf.Cos(angle * Mathf.Deg2Rad) * transform.GetChild(0).localPosition.x;
transform.GetChild(0).localPosition = new Vector3(localX, 0, 0);
Angle is the rotation value in radiants of the parent object. I want the child to be closer to the parent when the angle increases but when I click play the position of the child is always 0 (in terms of local position). I did a debug to check the values of the Cos function and they are correct so I don't know why i get this error. Can someone help me?
Comment
"Angle is the rotation value in radiants" - so why are you multiplying it by $$anonymous$$athf.Deg2Rad
?
Sorry, my mistake. Angle is in degrees so i have to convert it to radiants.