Child -> Parent Question

Is it possible to stop Childs moving when moving the parent without detaching them??? If so, how :?: :roll:

rgds

zemog (Crank5 :smile: ?!?)

You could do it in theory by moving the child object locally by the same distance in the opposite direction whenever the parent moves (but it gets complicated when the parent also rotates). Generally, if you need to keep a child object still while moving the parent, then it implies you don’t really want it to be a child object at all.

If you are using the parent to group objects together for easy access, then you might be able to make all of your objects children of an empty GameObject. If you position the empty at <0,0,0> then the children’s local positions will be the same as their world positions.

Isn’t it easier to set the childObject.transform.position = x
in the update?

For example:

var childObject : Transform;
var childLocation : Vector3 = Vector3.zero;

function Update()
{
  if(someCondition)
  {
    childLocation = childObject.position;
  }
  if(childLocation != Vector3.zero)
    childObject.position = childLocation;
}

the position is the absolute vector while the localPosition is the position compared to the parent so if you keep the world position and set it to that each frame i guess your ok.

Erm… easier that way, of course (wasn’t thinking) :sweat_smile:

Ok Iam using it only as a container for easier access, so I will make an extra empty object for thus.

Thank you Guys.