Casting to int has a a problem with negative values. While positive values are always casted to the nearest integer that is equal or lower than the given value, negative values are casted to the next greater value:
value (int)value
1.1 1
1.9 1
-1.1 -1
-1.9 -1
So a cast will always round towards “0”. You should use one of those instead:
Mathf.FloorToInt
Mathf.CeilToInt
Mathf.RoundToInt
depening on your needs. For example FloorToInt will return this
value FloorToInt(value)
1.1 1
1.9 1
-1.1 -2
-1.9 -2
so it’s always rounding down. CeilToInt will always round up and RoundToInt rounds up if the value is greater than 0.5 otherwise it rounds down.
Also i’m not sure why you compare to “1” and not “0”
Maybe something like this?:
// [ ... ]
int x = Mathf.FloorToInt(smoothPos.x) + 8;
int y = Mathf.FloorToInt(smoothPos.y) + 8;
if ((x % 16) == 0)
snapPos.x = x - 8;
if ((y % 16) == 0)
snapPos.y = y - 8;
// [ ... ]