This took a while to track down, but it is easy to reproduce, the Z axis numbers are WAY off when reported back by the transform.position of an object, I first started seeing this happen with my multiplayer games, but didn’t think too much of it, was blaming it on packet inconsistancies, then I created a new project to simply test the position of the player in a step by step movement system (has documented into other threads), this is so easy to test and program I am very supprised that others haven’t ran across this problem in Unity 2.6.1 on Windows.
Taking the code that I was helped with in another thread for simple movement, attaching it to the camera on a blank / empty project, and simply hit the play, it is that simple to setup the project and test, here was the code:
void Update()
{
if (Input.GetKeyDown("up"))
{
transform.position = transform.position + transform.forward;
Debug.Log("X:" + transform.position.x.ToString() + " Y:" + transform.position.y.ToString() + " Z:" + transform.position.z.ToString());
}
if (Input.GetKeyDown("down"))
transform.forward = -transform.forward;
if (Input.GetKeyDown("left"))
transform.forward = Quaternion.Euler(0, -90, 0) * transform.forward;
if (Input.GetKeyDown("right"))
transform.forward = Quaternion.Euler(0, 90, 0) * transform.forward;
}
Thats all the code you need in your entire scene to test and see this problem. When you click on the up arrow to move forward, you would expect the following results:
X:0 Y:1 Z:1
Now, click on the right arrow and hit the up arrow, you would expect to see:
X:1 Y:1 Z:1
However, my results on this very first movement was:
X:1 Y:1 Z:0.9999999
Not horrible yet, just off by a very slight float amount, now hit the left arrow and then the up arrow again, you would expect to get:
X:1 Y:1 Z:2
Now keep repeating this process a few more times:
Eventually if you keep playing with it, Z will jump by 4 or 5 places, but your position will be different than reported by X, Z coordinates, if you hit the Up arrow, Right Arrow, Up arrow and Right arrow consitantly, you should only be moving X, Z by +/- 1 spot because you are moving in a circle, but it will jump by 4 in this small demo.
http://screencast.com/t/NDA4NWM4Yj
Now, in this video, all I did was move in a perfect square, 4 spots, and both X and Z eventually jumped, I have successfully tested this with different versions of code to move the camera 1.0f at a time. This can also be noticed on larger scale smoother movement systems including the normal pill player code in the unity package, it isn’t very obvious because it is correct in the next game frame or two, however, this glitch has the data sent across the network to other players causing them for 1 game frame or 2 game frames to be way out of position, and unless you have a game with a simple movement or single position movement, you will not notice it, if at all.
I wouldn’t have noticed it as much without the data being corrupted and thinking it was just me and my packets, as you can see I didn’t even have the server running so I didn’t have any other players in the scene, this is a pure data example. So take that code, attach it to a camera, use the up and right arrows ONLY and use them rapidly as in Up, Right, Up, Right, etc and keep yourself in a square movement and watch your numbers. This is causing me hell with my games at the moment, especially my turn based multiplayer dungeon game, players jump to different areas of the dungeon when this happens and then jump back, and that just will not do.