- Home /
Assigning Parents position and rotation to Variable
Hey All,
How can I assign a parents position and rotation to a variable?
Thanks, Fenlig
Not sure what you are trying to solve here, and in what language:
var pos = transform.parent.position;
var q = transform.parent.rotation;
Answer by Baalhug · Dec 02, 2013 at 08:14 PM
The object "transform" returns the object the script is asigned to. So if you have an object, a box for instance called Mybox, and you assing a script to it (by dragging the script into the box in the editor, for instance) and finally you type this in the script:
Transform varpos; varpos=transform;
now varpos has position, rotation and scale of the parent of the script (Mybox).
If you have another object MyBoxParent which is the parent of MyBox normally parent and children transform (position, rotation and scale) will be the same, because when you modify parent's transform you modify automatically children's transform. But if you want to assign it to a variable anyway, you can use:
Transform varpos; varpos = transform.parent;