- Home /
Question by
NurullahC · Jan 30, 2017 at 07:37 AM ·
c#child objectlocalpositionparent and child
How can Use Child Local Position
Hi everyone, I instantiate object. And this object has a parent object it means instantiated object is a child another object. I am trying change child objects local position using this code
Vector3 ileri =new Vector3(0,0,0.2f);
this.gameObject.transform.localPosition += ileri;
But this code not use child object local position using parent local position how can fix it?
Comment
Best Answer
Answer by NurullahC · Jan 30, 2017 at 10:54 AM
I solve my question this way,
var forward = transform.TransformDirection(x.transform.position);
transform.localPosition += forward *y ;
X is Vector3 variable. I use to direction of target object. Y is float variable. I use for speed.
Your answer
![](https://koobas.hobune.stream/wayback/20220612105907im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Moving platforms in unity 3D 1 Answer
Get Local Mouse Position from the center of the Gameobject clicked on 2 Answers
Constrain local X movement 2 Answers