Isometric Z as Y tilemap world position to correct cell position - Wrong offset

I have a problem regarding the translation of mouse raycast positions into the isometric grid cell position.
As you can see, there is a huge offset between the raycast hit (red) and the translated tile (green):

I am using the following raycast code:

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

RaycastHit2D hit = Physics2D.GetRayIntersection(ray, Mathf.Infinity, GroundLayerMask);
if (hit.collider != null)
{
    LastHit = hit.point;
    Vector3Int cell = World.Instance.Grid.WorldToCell(LastHit);
    if (cell.x >= 0 && cell.x < World.SIZE && cell.y >= 0 && cell.y < World.SIZE)
    {
      cell.z = GroundManager.Instance.Map[cell.x, cell.y].MapHeight;
      if (LastPosition != cell)
      {
         if (World.Instance.Ground.HasTile(LastPosition))
         {
             World.Instance.Ground.SetColor(LastPosition, Color.white);
         }
         if (World.Instance.Ground.HasTile(cell))
         {
             World.Instance.Ground.SetTileFlags(cell, TileFlags.None);
             World.Instance.Ground.SetColor(cell, Color.green);
             LastPosition = cell;
         }
      }
   }
}

The z position is pulled from my heightmap:
GroundManager.Instance.Map[cell.x, cell.y].MapHeight

Could anyone please help me with the mathematical translation that is needed?

In 2D, you use OverlapPoint to see what overlaps a 2D point and not a raycast.

GetRayIntersection is more specialized and used in those odd pseudo-3D cases and it emulates a 3D ray but in the end, it’s 2D physics and you only need to perform an OverlapPoint in reality.

I figured out that
Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
actually produces the same position.
Unfortunately, this still does not resolve the offset issue. Anyone had previous run-ins with this and was able to solve them?

You seem to be ignoring my advice above then.

The world mouse position can be used to perform an OverlapPoint. If it’s true it returns you the collider. You use the point you passed to OverlapPoint directly in the WorldToLocal. No need for fake rays in pseudo-3D etc. This is all 2D.

For anyone out there wondering, I found the solution to translating isometric z as y positions into the world to cell method:

Note that World.Y_SCALE represents the Grid.cellSize.y value and that World.Z_SCALE represents the Grid.cellSize.z value.

Using the following code, I am finding the correct cell:

public const float DELTA_Y = World.Z_SCALE * World.Y_SCALE * 0.5F;

public static Vector3Int FindGroundTilePosition(bool debug = false)
    {
        if (GroundManager.Instance == null || GroundManager.Instance.Map == null) return Vector3Int.zero * -1;

        Vector3 pos = Camera.main.ScreenToWorldPoint(GameManager.Instance.InputHandler.MousePosition);
        pos.z = 0;

        Vector3Int cell = Vector3Int.one * -1;
        pos.y -= (World.MAX_HEIGHT + World.Y_SCALE) * DELTA_Y;
        for (int y = World.MAX_HEIGHT; y >= 0; y--)
        {
            cell = World.Instance.Grid.WorldToCell(pos);

            if (GroundManager.Instance.Map[cell.x, cell.y].Height == y)
            {
                cell.z = y;
                break;
            }

            pos.y += DELTA_Y;
        }

        if (debug)
        {
            for (int x = 0; x < World.SIZE; x++)
            {
                for (int z = 0; z < World.SIZE; z++)
                {
                    World.Instance.Ground.SetColor(new Vector3Int(x, z, GroundManager.Instance.Map[x, z].Height), Color.white);
                }
            }

            if (cell.x >= 0 && cell.x < World.SIZE && cell.y >= 0 && cell.y < World.SIZE)
            World.Instance.Ground.SetTileFlags(cell, UnityEngine.Tilemaps.TileFlags.None);
            World.Instance.Ground.SetColor(cell, Color.blue);
        }

        return cell;
    }