Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How to find a game objects local space coordinate values?

Discussion in 'Formats & External Tools' started by MMeyers23, Sep 15, 2021.

  1. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    Hi,

    I am trying to perform a simple task but unfortunately finding it more complex than I originally anticipated.

    I am creating an Amplify Shader Editor shader that uses the vertex position node (same as the 'position node' in Shader Graph), which I understand to represent the position of vertices in object space. However, I do not understand how to identify the actual coordinate system used for my game objects. My ultimate goal is to map each axis (x,y,z) of the vertex position coordinate system from 0 to 1. For example, after doing this operation and plugging the result for x into the color node, it should transition from black to white across the object in the x direction.

    Different objects appear to have different magnitudes for object space coordinates. For example, a Unity plane appears to have object coordinates (-5,5) in x and y axis. I have to add 5 then divide by 10 to map them to 0,1. For a Unity sphere, quad, or cylinder, the coordinate system is (-0.5,0.5) and for objects imported into Unity I have no clue what the coordinates are.

    Since I need to do math with these values, how can I tell the max and min in object space for a given object? I thought they would be the same for all objects (ie -0.5,0.5)... This way I can properly use the vertex position node.

    Please let me know if I need to clarify further with pictures.

    Thanks!
     
  2. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    Okay, just in case anyone ever has the same question, I figured this out about an hour later despite not finding any good info online. For objects imported from Blender, there are multiple export options for FBX. If you use the 'FBX Units Scale' option, then when you import your FBX into Unity the scale will be 1. Otherwise, the default export option is 'All Local' and I think this typically results in your object having a scale of 100 when imported into Unity.

    picture3.png

    In order to find the object space coordinates (or vertex coordinates) for objects imported from Blender, you have to look at the 'dimensions' properties of your object in Blender. For my object, the dimensions were 350m by 350m in the x and y.

    picture1.png

    You then must factor in the scale. My object had a scale of 100 when imported into Unity. So I took 350 and divided it by 100 to get 3.5. The vertex coordinates typically go from (-0.5,0.5) for objects that are 1 meter, (which I think is the default for most Unity objects?) so in my case, they went from (-1.75,1.75) for a total length along the X axis of 3.5 meters. To remap this to (0,1) I just had to add 1.75 then divide by 3.5.

    picture2.png

    If the scale was 1, the vertex coordinates would range from -175 to 175 on my x axis. Again, this is determinedby the dimensions of the object (in meters) in Blender.

    Hope this helps someone else.

    Goodnight.
     
    Nintoryann likes this.