Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mesh vertices change object center

Discussion in 'World Building' started by FuturePilot1701, Jul 31, 2019.

  1. FuturePilot1701

    FuturePilot1701

    Joined:
    Jul 31, 2019
    Posts:
    8
    I am trying to generate a sphere of any size and add noise to the surface. I got to the point where I can generate the sphere shape, then apply a mesh and a material with the noise texture on it. However, given the way I generate the noise, the noise changes based on the location of the object that has the generation script attached. So I simply moved the object away from 0, 0, 0, and then when I clicked play, the object generated the circle off center, and appeared to change the center of the object from where it was. So I created a new script to go through the whole process step by step again. And I found that everything was good until I write "mesh.vertices = vertices" (vertices being my list of vertices. If I run the program with this line included it moves the center of the object down and to the right. Is the a normal thing when applying mesh vertices?

    Before:

    before.PNG

    After: after.PNG

    Literally all I did to have this happen was un-comment the line "mesh.vertices = vertices"
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well if you don't do "mesh.vertices = vertices" then you aren't doing anything at all. You're just building an array and throwing it away.

    So yes, it's normal that when you assign new vertices to a mesh, the mesh changes. ;)
     
  3. FuturePilot1701

    FuturePilot1701

    Joined:
    Jul 31, 2019
    Posts:
    8
    but why did the center point of the entire object change?
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Because, apparently, your mesh vertices are not centered around 0,0,0.

    (Keep in mind that vertex positions are always given in local coordinates.)
     
  5. FuturePilot1701

    FuturePilot1701

    Joined:
    Jul 31, 2019
    Posts:
    8
    the vertices arent centered around the obejcts 0,0,0?
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yep. So it appears. (Of course since you haven't shown us the code that generates the vertices, we can only speculate from the symptoms you've described.)