Prepare your 3D Models
Last updated
Last updated
Pivot of the 3D model should be centered in x and z axis
The 3D model should have a collider attached so we can interact with it after it is placed.
The Y axis of the pivot point is handled automatically on runtime, no need to worry about that
Most of the used 3D models in this asset already have the correct pivot point.
E.g. For the house type 06 the pivot is already on y=0 and centered across the x and z axis.
If this is the case for your models you can simply create a prefab out of it and assign it to the proper placeable object.
Obviously not all 3D Models will use a perfectly centered pivot.
For showcasing the issue I have created an example object with a wrong pivot. As you can see the pivot is not centered in the x and z axis. The y position of the pivot is not even at the bottom of the mesh, so instantiating the object at 0,0,0 position would result in the object being half under the floor.
Let’s try out to place this object on the grid:
The left example is without rotation and the right one with rotation applied.
To fix the previously described issue you simply need to create an empty gameobject and add the CenterMeshXZ to this object. Then add the 3D model as a child of this object.
You can simply click on “Center MeshXZ” and the pivot is automatically fixed for you.
However you do not need to use the button,since the script will be executed on runtime which will fix the pivot. The most important thing is just that the script is attached to the parent object.
Now your model is ready to be added to a placeable object and used in the grid system.
You can see that the automatic grid pivot offset calculation at runtime perfectly handles the height offset. However if you try to rotate the object you can see that the object is not anymore in the marked grid cells where it actually should be.