- Home /
Why this prints (0, 0, 0): Debug.Log("" + ((new Vector3(1, 0, 0)) * 0.016f));
Just started a new project to prototype an idea I want to show in a video and starting having a persistent BUG I'm trying to fix.
One of my automatic "Walkers" is not moving as it should, so I printed some variables in Debug.Log to see what may be happening. And I found the following:
Debug.Log("" + ((new Vector3(1, 0, 0)) * 0.016f));
// prints (0, 0, 0)
Now, I'm aware of floating point round errors and Unity comparing vectors again a certain minimal error constant. But, and correct me if I'm wrong, (0.016, 0, 0) should be a valid vector. And even if it is of magnitude less than 1, it should still be fine, able to be normalized to (1, 0, 0) and so on.
Answer by MikaLikeABoss · Nov 24, 2019 at 01:36 AM
Found the following:
Actually, this prints fine:
Debug.Log("" + ((new Vector3(1, 0, 0)) * 0.016f).x);
// prints (0.016, 0, 0)
Debug.Log("" + ((new Vector3(1, 0, 0)) * 0.016f).normalized);
// prints (1, 0, 0)
It seems the BUG in my code was due to me forgetting about unity physics operating on units per second. I have a public field to set the speed of the "walker", and it is mean to be in units per second. It's already on the same scale than unity physics so no conversion is required. I was multiplying by one of the fields of Time.
to convert to units per update, something that isn't required at all if you are already working in units per second.