- Home /
transform set world position
I have a wall which is a childobject of a box which is again a childobject of something else. I want that wall (for example the western wall of the box) to be on the edge of the screen, but the edge position differs offcourse between all screen sizes (I'm programming for mobile phones).
So I need to set the wall's transform.z to
cam.ViewportToWorldPoint(new Vector3(1, 1, cam.nearClipPlane)).z;
but I can only set it's local position. Is there way to set its absolute position and let Unity calculate the correct stuff for its local position relative to the parent?
Answer by ligangwei · Jun 13, 2019 at 08:19 PM
I think you might be looking for this: InverseTransformPoint
Something along the lines of wall.position = wall.InverseTransformPoint(cam.ViewportToWorldPoint(new Vector3(1, 1, cam.nearClipPlane)).z);
?
Edit: hold right there, wth am I talking about, isn't .position already its global position?
Answer by YetAnotherKen · Sep 02, 2019 at 09:00 PM
if you want a child to be positioned relative to a parent, it has to have the parent set . ie
cam.transform.parent = parentObject.transform;
you can orient the child relative to the parent using transform.localPosition of the child.
Your answer

Follow this Question
Related Questions
How can I get Rigidbody.MoveRotation to rotate in world space on two axes? 1 Answer
Updating world coordinate according to world points 1 Answer
Camera, Player, Tilemap Grid are all on (0,0,x)-2D world but they aren't in the same position 0 Answers
Dragging panel(prefab) from screen space canvas to world space canvas and scaling to fit 0 Answers