Search code examples
c#unity-game-engineaugmented-reality

How to get details (Position ,Rotation, Scale) of the Game Object that is placed in real world as AR?


When I place a game object (e.g.: Cube) in the real world with the help of AR using Unity, I want to receive detail of that game object like the position, rotation and scale in xyz plane separately. Will it be possible to get it in text form?


Solution

  • The easiest way to get position, rotation and scale separately would be like this:

    Vector3 worldPosition = this.transform.position;
    string worldPositionStr = worldPosition.x + ", " + worldPosition.y + ", " + worldPosition.z;
    

    assuming the script is attached to the object in question. For rotation use this.transform.eulerAngles instead of this.transform.position and this.transform.lossyScale for scale (have a look at the documentation of each of those fields to better understand them).

    You should keep in mind though that these values are in the space of the current AR session. So these values depend on where you start the AR session and might change each time you restart your session.