hi,
I’m stuck on how I can get a child to move but keeping the parent at the same distance once its move to the child, so if the child is at 0,0,0 and the parent distance is 9,9,0, but I move the child to 100,100,0. I want the parent to be at 109,109,0 when I move it to the child’s position. basically, I want the distance kept the same where ever I move the child.
any help would be highly appreciated.
One thing you can do is save your position difference to a variable, and add it to your parent whenever you move you child.
/*
Script is attached to parent
*/
public Vector3 parentOffset;
void Awake(){
parentOffset = GetComponentInChildren<Transform>().localPosition;
}
void Update{
// If targetPosition is varible that contains the position that is to be moved at then
// move you child at targetPosition
// move you parent at targetPosition+parentOffset;
}
// just remember targetPosition is also a Vector3.
Hope this helps.