title: Distance between two grid cells, with no diagonal
body: <p>I've been working on a small project for some days, everything was working fine until I changed my "map" implementation to be the same as in the game (Dofus) I'm based on (it's a little helper for the community).</p>
  
  <p>Basically, I've a grid layout rotated at 45° (see image below), contructed from top left to bottom right. Every cell as an xIndex and zIndex to represent where it is (xIndex ; zIndex) on the image, and I just want to get the distance between two cells, without traveling diagonally. </p>
  
  <p><a href="https://i.stack.imgur.com/kqSIY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kqSIY.png" alt="Grid"></a></p>
  
  <p>As I tried to explain on the picture:</p>
  
  <ul>
  <li><p>GetDistanceBetweenTiles(A, B) should be 3</p></li>
  <li><p>GetDistanceBetweenTiles(A, C) should be 5</p></li>
  <li><p>GetDistanceBetweenTiles(B, C) should be 2</p></li>
  </ul>
  
  <p>I found the "Manhattan distance" which looks like it is what I want, but it's not giving me the values above.</p>
  
  <p>Here is the code: </p>
  
  <pre><code>private int GetDistanceBetweenTiles(MovableObject a, MovableObject b)
  {      
      //int dist = Mathf.Abs(a.xIndex - b.xIndex) + Mathf.Abs(a.zIndex - b.zIndex);
      int minX = a.xIndex &lt; b.xIndex ? a.xIndex : b.xIndex;
      int maxX = a.xIndex &gt; b.xIndex ? a.xIndex : b.xIndex;
      int minZ = a.zIndex &lt; b.zIndex ? a.zIndex : b.zIndex;
      int maxZ = a.zIndex &gt; b.zIndex ? a.zIndex : b.zIndex;
  
      int distX = (maxX - minX);
      int distZ = (maxZ - minZ);
  
      int dist = Mathf.Abs(maxX - minX) + Mathf.Abs(maxZ - minZ);
  
      print($"Distance between {a.name} and {b.name} is {dist}");
  
      return dist;
  }
  </code></pre>
  
  <p>Any help would be gladly appreciated.</p>
  
  <p>If it can help, <a href="https://elio-project-dofus.herokuapp.com/" rel="nofollow noreferrer">here is the project working with the first map</a> implementation I did (but not translated yet).</p>