title: Grid Based Movement for a Block Sliding Game
body: <p><a href="https://www.gamesmen.com.au/rush-hour-traffic-jam-logic-board-game" rel="nofollow noreferrer">https://www.gamesmen.com.au/rush-hour-traffic-jam-logic-board-game</a></p>
  
  <p>there was this game that i try to recreate it in Unity. i've try to make the sliding blocks script, and it works. let's just say that i make it with a Grid, yes, that Grid where i can put tiles on it. so how can i make the blocks snaps on the Grid? especially if the block is more than 1 tile long?</p>
  
  <p>they way how it works is that i use OnMouseDown at the moment because i've planned to built it on Android but now the problem is that i don't know how to make these blocks snap to grid with OnMouseUp. </p>
  
  <p>so far here's the Code for the Blocks</p>
  
  <pre><code>private void GrabABlock()
      {
          if (Input.GetMouseButton(0)) {
              Debug.Log("blockGrab"); 
              mousePos = Input.mousePosition;
              mousePos = Camera.main.ScreenToWorldPoint(mousePos);
              BlockPosX = mousePos.x - this.transform.position.x;
              BlockPosY = mousePos.y - this.transform.position.y;
              Grabbed = true;
              if (Grabbed == true) {
                  mousePos = Input.mousePosition;
                  mousePos = Camera.main.ScreenToWorldPoint(mousePos);
                  switch (BlockDirection)
                  {
                      case BlockShape.Horizontal:
                          HorizontalMovement();
                          break;
                      case BlockShape.Vertical:
                          VerticalMovement();
                          break;
                      case BlockShape.Square:
                          OctaMovement();
                          break;
                  }
              }
          }
  
      }
  
      private void LateUpdate() // Snap to Grid
      {
          mousePos.x = Mathf.Floor(gameObject.transform.position.x / 1f) * 1f;
          mousePos.y = Mathf.Floor(gameObject.transform.position.y / 1f) * 1f;
          pivot.transform.position = mousePos;
      }
  </code></pre>
  
  <p>my expectation is that the block's pivot detects the each tiles of the grid, and snaps into it onMouseUp</p>