- Home /
Child world location
Info.... I have a parent Cube with a separate collision box on each side attached to an empty as its children. Each empty is named CubeSideX as x is 1-6.
I am rotating the parent as such (Temporarily)
if (Input.GetKeyDown(KeyCode.Z))
{
transform.Rotate(90, 0, 0);
}
I Store the Y position of each CubeSide with this
CubeSide1PosY = CubeSide1.transform.position.y;
I then determine which side has the highest Y value and put a "TOP" Tag on it.
Question.... Why does My CubeSide Position not change as I rotate my parent? I thought transform.position gets the world position?
Answer by NoGo86 · Nov 12, 2012 at 04:53 AM
Instead of the accessing the child position via gameobject.transform.position.x ect. I set the (x, y & z) axis to var's on each child and accessed them from the parent with
var xPosSide1 : float = transform.Find("Side1").GetComponent(ScriptSide).xPos;
its a bit more code then I would like but it does what I need.
Answer by Montraydavis · Nov 02, 2012 at 02:47 AM
If
if (Input.GetKeyDown(KeyCode.Z))
{
transform.Rotate(90, 0, 0);
}
is what you are using, I don't see where specify it rotating to face the object.
Are you trying to have the Target look at the Object? ( Does Transform LookAT () work for you ? )
function Look ( )
{
gameObject.transform.LookAt ( Target.transform ) ; // Param Type 'Transform'
}
If you're trying to get the child to rotate along with the parent, you really shouldn't change your rotation values... It does this automatically.
The transform.Rotate is used on the parent not the child. What is happening is when my parent cube x rotation 0 the child position y = 0. When my parent's x rotation is 90 the child's y still is 0 even tho it is really not.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Child versus Parent rotations 3 Answers
force child rotation to zero? 2 Answers
Ignore parent Rotation 1 Answer
Rotating a parent object so that child is at the closest possible position to another object 1 Answer