- Home /
Position as a child
Hello everyone, i want to know the difference between the object position when it's "free" and when it's a child of another object, i was trying to make this but it didn't actually work,
have an object with a Y position (as a child)is equal to 2.5 -in some point of the game i want to to go to a Y position equal to 0 -then in another point i want it to get back to 2.5 when i tried to do it, the object did go to 2.5 but in reality i didn't want it to be there, the position am seeking is 0.4, cause that is the real Y position when i "un-child" the object, i tried my code with the 0.4 and it worked
the question is, how to work with the "2.5" value but make the script understand it as a 0.4
thank you
transform.position is always relative to WORLD SPAC$$anonymous$$ transform.localPosition is the position of the transform relative to it's immediate parent.
Answer by hellaeon · Sep 03, 2013 at 10:56 PM
You have to remember relative movement. If you yourself are a parent object and your carrying a phone, if you move the phone around it won't change your position in the world if you stand still.
With that idea, to the phone you are it's world, you are it's 0,0,0.
What you see in the phones transform position are its coordinates starting from this 0,0,0 (you)
It is important to understand this by doing a few tests.
1) create a parent object at (0,0,0)
2) add a child object
3) set the child transform.position to (0,0,0)
3) move the child to (5,0,0)
4) now move the parent, the child moves with it, but the child transform.position won't change.
the child's position is shown in relation to the parent, which is the center of its world coordinate system To get the child's position in the main world coordinate system, you might want to try transform.transformPoint
You just have to remember when dealing with transform space, your parent is your child's (0,0,0) I would suggest doing a google on local space v world space.
@flaviusxvii thanx for the quick reply @hellseon thank you for the explanation, it helped a lot