0
\$\begingroup\$

enter image description here

So, I have X and Y game objects. I have a vector Z = X - Y which is indicated by the green line.

Also, I have a Parent game object and it has a Child game object. How do I move the parent such that the child game object is at the Point Y

I tried,

                  Z -= new Vector3(child.localPosition.x, 0, child.localPosition.z);
                  Parent.transform.position = Z

which is not working as expected. Thank you!

\$\endgroup\$
  • \$\begingroup\$ What does Z have to do with all of this? Just add Y - C.transform.position to the parent's position \$\endgroup\$ – Bálint Aug 2 at 18:04
1
\$\begingroup\$

Did you try something like this?

childToTarget = targetPosition - child.position;
childToTarget.y = 0;

parent.position+= childToTarget;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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