Snapping to Grid with Spacing (offset)
Greetings,
I use the function below to snap a moving gameObject to the grid :
private void SnaptoGrid()
{
var position = new Vector3(Mathf.Round(this.transform.position.x / this.gridsize.x ) * this.gridsize.x,
transform.position.y,
transform.position.z) ;
this.transform.position = position ;
}
but I need to add a float number as a spacing factor between each grid box. I attached a pic to illustrate what I mean. How should I change the code to accomplish this task ? Thanks
sampleee.jpg
(16.6 kB)
Comment
Your answer
Follow this Question
Related Questions
Move object to grid 1 Answer
Grid movement with a rectangular grid? 1 Answer
Spawn prefabs in a grid around the player 0 Answers
Hide Grid gameobject in the Game tab 0 Answers