- Home /
Record Object's Position
I was wondering how to correctly save an objects position into a variable.
I'm coding in JS, and I tried the following:
yPos = object.localPosition.y;
xPos = object.localPosition.x;
zPos = object.localPosition.z;
That didn't work, how would I go about doing this?
Thanks!
localPosition is used when the object is child of another object - it's the offset relative to the parent object. The absolute position is given by transform.position.
Answer by Eric5h5 · Aug 04, 2011 at 08:45 PM
objectPos = object.transform.position;
Assuming "objectPos" is a Vector3, and "object" is a GameObject.
okay so that would store the position of the object into objectPos. But now that it's a vector3 how do I tell the object to move there? I usually use object.transform.localPosition = new Vector3(x,y,z); But with all of the values stored in one variable I'm not sure how I'd code that.
Answer by omarcesar · Feb 02, 2016 at 05:30 PM
this plug-in helps record movement of any 3d object, including avatars or complex object with multiple children.. all you do is check one flag. Easy to import and use. check out the demo: https://www.youtube.com/watch?v=Ay-wuj5PvHU
link in asset store; https://www.assetstore.unity3d.com/en/#!/content/17836
Your answer
![](https://koobas.hobune.stream/wayback/20220612170521im_/https://answers.unity.com/themes/thub/images/avi.jpg)