Debug.Log(Vector3.Angle(ray.direction,hit.normal)); HELP!


I have a ball rolling on a floor. The floor is perfectly flat.
I use Vector3.Angle(ray.direction,hit.normal) to get an angle of the ball to the floor.
When the floor is perfectly flat the angle returned is 180 degrees. This occurs when the ball is still and when it is rolling.

On some levels the angle stays at 180 without changing at all. On other levels though, when the ball is rolling around the floor, the angle changes slightly by a few digits.

The crazy part is, i use a floor prefab which i tried placing on a level while it’s running. If it was a level where the angle returned was always 180, then the new floor angle would also return 180 when the ball rolled over it.
But when i put the floor prefab in a level where the angle changed while the ball rolled then the new floor would produce the same effect EVEN THOUGH ITS THE SAME EXACT PREFAB USED FOR BOTH LEVELS!!!

Please help, im really at a loss here… thanks.

EDIT: Okay tried doing Debug.Log(hit.normal) to see if that changes on different floors and it doesnt. The value returned is always (0.0,1.0,0.0) on FLAT, NON ANGLED surfaces. This happens on every single level.

It stands to reason then that it’s the ray.direction that causing the problem, but i dont understand how considering im using the same exact script for all my levels?

EDIT 2: OK EVEN MORE WEIRDNESS. If i create a brand new scene with just a ball, floor, camera, light. When i run it multiple times, the angle is 180 all the time. BUT WHEN I CHANGE TO ANOTHER SCENE AND CHANGE BACK TO THAT SCENE THE ANGLE STARTS CHANGING!!! what could possibly be happening?!?!?

EDIT 3: OKAY so it all boils down to this… If i delete the ball in any scene and replace it with a new prefab ball then the angle stays 180 degrees no matter how many times i run it. I save and load a different scene, and then reload the previous one again. And the problem comes back. WHY???

If shadowProjector refers to a separate object which follows the sphere in Update, the problem may be caused by different script execution order: when the projector Update executes before the sphere’s one, it follows an outdated sphere position and cause this weird behaviour (looks exactly like in your video). Deleting and adding objects may affect the order scripts are executed, what could explain why it gets screwed up after deleting and recreating the sphere.

If this is the problem, move the projector code that follows the sphere from Update to LateUpdate, so that it will always execute after the sphere has moved in the frame.