Need help with snapping Prefab assets to grid in game
Hello,
My name is Dean. I got into Unity and C# programming recently to expand my knowledge of video game development. Currently I am trying to make an isometric, construction management based game (think RollerCoaster Tycoon for example) but I am having trouble in snapping the prefabs to a grid.
Whilst it's great that I've achieved this much already with the development of my game, I'm not happy that the placement of each prefab requires precise placement in the game. Each asset is roughly 5' x 5' inches, (Floor Tile and Fizz Machine especially) so ideally I want each grid space to be that, at 5' x 5'.
Also, when building the Floor Tile I would like to know how to "click and drag" a selection so that the path is created quicker, like in the same manner Streets or roads are built in Sim City 4. I think the current placement (having to click and re-click the Floor Tile UI button) of the prefabs for the path is very tedious.
I have the code here for your viewing and assistance.
Any advice on this (or ideally where to go to get my feet wet in my desire) would be fantastic. Many thanks Unity community.
Dean.
Answer by Ho-Runner · Jan 24, 2016 at 09:10 PM
@AcidicPaper, hi there. yeah snapping prefabs is easy to do. I suggest that your models (if you made them yourself) are set to the origin (0,0,0) before you export them to an .FBX, then once you have them in Unity, while you are in the transform tool, hold 'v' to access vertex snapping. it will allow you to snap the vertices of two objects together. hope this helps!
Answer by AcidicPaper · Jan 24, 2016 at 09:13 PM
@Ho-Runner Hi! Thanks for your speedy reply!
The objects in question were made by myself in SketchUp. So, will I need to place them at the 0,0,0 origin before putting them in again?
Keep in mind these are prefabs as well, I dont have them in the hierarchy because the UI is responsible in placing them on the game map.
@AcidicPaper, I would recommend it as if you bring these objects into the scene and they were not centered in the origin when they were exports, the objects will rotate strangely. so yes I recommend centering your objects before attempting to snap them. I have never used sketch up, only maya and 3ds max.
I'm sorry. How do you mean by this? In Layman's terms :P
ok. open up whatever modeling program you are using and open your objects. use the transform tool and set the position of your objects to (0, 0, 0). then export the objects in an FBX file. then put these fbx's into unity
Your answer
![](https://koobas.hobune.stream/wayback/20220612061540im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
snap object to another object 2 Answers
Moving an object a fixed amount on its local axis 1 Answer
How do I keep the player with rigidbody from going through the wall 1 Answer
How To Move A Ball Using Touch Input? 0 Answers
A script that doesn't allow moving objects to go through non-moving objects? 1 Answer