transform.Translate.y(-10) translates by -9.999998?

Everything was working just fine, until I rotated the parent 270 about x. Now when I try to move by -10 the object moves -9.999998, and also moves z by 0.000005. If I manually enter -10 in the transform’s position, the code works properly (I’m calling actions based on position of the object).

I’m really just teaching myself how to do this game business, all I need is a little advice on what the hell is happening here!

Thanks in advance

This is a common thing in game engines, and without getting into details, it’s to do with floating point numbers and rounding errors. You’ll notice it happening with rotating objects, too - getting 89.999999 instead of 90 as a rotation, for example.

It’s fine in the vast majority of cases, unless your game’s code is extremely dependent on floating point calculations being 100% accurate. And if that’s the case, you can for example use Mathf.Epsilon and an if statement to check for equality of two almost-equal floating point numbers, as such:

if (a - Mathf.Epsilon < b || a + Mathf.Epsilon > b) {
    //a and b are effectively equal
}
else {
    //a and b are effectively not equal
}