Search code examples
c#pivotmeshunity-game-engineplane

Unity5 Plane pivot point creating


I created a 50x50 planes with c# script. I used vertices, UV and triangles. And those planes making an area. So no problem there. But my Plane_0_0 which is the first one is positioning at the center. I need each plane pivoting to bottom-left. How can i pivoting bottom-left with script?


Solution

  • Okay, I think I've got it. You want the bottom-left corner "tile" to be the center of the whole "tileset" / "map", so if and when you rotate "everything", that should be the center.
    Okay, it's easy. What you need to do is, make that Plane_0_0 tile the parent of the rest of the tiles (set the .Parent property of all tiles you want to be part of your pivoting to the "pivot tile" GO).

    Later on, you can change this. So if e.g. some other tile should be the pivot center, you can "reset parenting". BUT reparenting is an expensive routine.


    EDIT
    As (like I wrote above) reparenting is an expensive operation, I was thinking about alternatives and this is what I found I would use: create a GameObject (let's say another plane) without mesh renderer, collider, etc and pull it out to the size of the field (in editor). Make this the parent of all the tiles in the scene. Then, whenever you need to 'pivot' everything, you can go for parent-plane's RotateAround, marking the rotation center whereever you wish (e.g. "above" the bottom-left corner tile).
    I would also modify the standard Unity Plane and remove Mesh Collider from it and replace it with a simple Box Collider, save as prefab and use that prefab as my tile to save some computing time (if planes' job is nothing else but to serve as a plateau).