Player's position in inspector isn't real position

I’m making a tile based movement game and I’m using Vector3.MoveTowards() to move the player. When I play my game, whenever the player’s x or z position are supposed to be 0, they become random numbers in the inspector that are way off with lots of digits after the decimal. My script for the player isn’t acting how it’s supposed to be when it hits walls when their position is supposed 0 for x or z.

My script detects collision by looping through all the obstacles and checking if the position of the obstacle is the same as what position the player’s going to go to.

Is this a glitch? Is there any way to fix this?

Sounds like your player’s position is “not quite” zero. Due to the way floating point numbers work, this can happen for various reasons when performing arithmetic on floats. You should check for collisions by using the distance between the objects positions with some tolerance.

if (Vector3.Distance(playerPos, otherPos) < 0.1f)
{
    // close enough to consider overlapping
}

What you may be talking about is scientific notations, they are used either when a value is extremely small or extremely large. This is common with floats and so it’s recommended to instead of checking if a float is 100% equal to another float, see if it is approximately equal. Unity’s transform uses Vector3’s which are just 3 floats really.

I’m not too sure if Vector3 has an approximation method so here is one that you can put into your script:

bool Vector3Approximate(Vector3 a, Vector3 b)
{
    if (Mathf.Approximately(a.x, b.x) && Mathf.Approximately(a.y, b.y) && Mathf.Approximately(a.z, b.z)) return true;
    return false;
}

If the vectors you enter are roughly the same, it’ll return true, otherwise false. So you can test by entering:

Vector3 potetialCollider = /*the tiles position you're testing*/;
Vector3 futurePlayerPos = /*the future player pos*/;
if (Vector3Approximate(futurePlayerPos, potetialCollider))
{
       print("Detected Collision");
}