Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Wrong Y & Z position after snapping. Tried local and global, with parent and without

Discussion in 'Editor & General Support' started by Thor20, Nov 28, 2022.

  1. Thor20

    Thor20

    Joined:
    May 22, 2014
    Posts:
    2
    Hi there, I'm sure this is a simple problem to solve but it is driving me crazy trying to make a hex grid.

    When I snap a duplicate to another copy, the Y & Z get new values even if the object hasn't moved on that axis, I can replace the value with 0 and it doesn't move but to do this manually on every level would take a while and I need the positions to be correct when read by the code.

    I have tried assembling with local and global transforms activated as well as with a parent attached and without one but get the same issue.
    I just have a simple hexagon model I made in Blender.
    I have been using V to snap the models to the geometry.

    Any help would be appreciated, not used Unity in a while and still learning as well as picking up Blender after a long break from 3DS max.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,962
    Position in the Transform inspector is always local... are you sure this is what you're seeing?

    Try tearing off the object from its parent, that will reveal its position.

    I would make a prefab out of it with an extra NON-rotated object at the top. Otherwise Blender objects come in (-90,0,0) rotation.
     
  3. Thor20

    Thor20

    Joined:
    May 22, 2014
    Posts:
    2
    I have an empty game object at the top of the prefab's hierarchy but the duplicate's Y values vary between -1.6 and -2.8 when they are all level with the original at 0,0,0.
    I experimented with cubes and don't get the problem so must be something to do with the model, maybe because the origin is in the top centre?

    I may be able to work around it in code or just selecting the hexagons after the level is built and changing all the Ys at once or set Y position when their scripts start.

    Just thought I should ask so I don't keep running into the same issue.

    Thank you for your advice!
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,962
    Try another model. Try a cube primitive. I don't see how that could be related though, since the inspector doesn't look inside meshes.
     
  5. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    I doubt they are -1.6 and -2.8. I would guess that the inspector actually has the value of
    -1.6...e-8
    , which is scientific notation for a number like -0.000000016. This is a value that is very close to 0 but not actually 0. This is an artifact of how floating point numbers work and is to be expected when working with them.

    Don't architect your code to depend on exact values for floats. Instead use rounding and/or relative comparisons (>=, <=, >, <) to perform your calculations. If you explain what your code is trying to accomplish, perhaps we can help you make the logic less dependent on exact values.
     
    Last edited: Nov 29, 2022
    PraetorBlue and Kurt-Dekker like this.