OK, this is patently weird (to me, anyway)
So I’ve been trying to get the degree on a single local axis between two points for a while now, and that, in and of itself works fine.
However, I also need to compare this angle to another angle, and now I’ve noticed something odd:
As far as I understood, the transform.forward parameter should always hold the global direction the object is facing, however, for me it only seems to update if I manually assign the forward Vector in a script (It also correctly displays the changed, new rotation in the editor and game view). If I simply change the rotation either from within a script or by using the direct editor controls, the forward Vector’s value doesn’t update.
This is true both for main GOs as well as their individual children.
I thought that transform.forward was effectively identical with transform.TransformDirection(Vector.forward) (Which doesn’t do anything for me either), is this incorrect?
BTW, I’m using the most current version of Unity (Non-Pro)
Any help will be greatly appreciated.
I have never had any problems with transform.forward
. Not to say that you haven’t discovered a bug, but I’m skeptical. How are you checking the value of transform.forward
? There are lots of ways that you can test the values of it, the easiest would just be to
Debug.Log(transform.forward);
in an Update()
and see what you get.
I think I had the exact same issue. It started after I crashed the editor.
Toggling enable on the affected script in the editor during run-time would make transform.forward report the correct value again.
I solved my problem by copying the whole script (Ctrl-A so I didn’t miss anything) into a new file with a different name.
Conjecture Warning → Does Unity have meta-data of script files? That might explain it.
(I know I’m 5 years late, this is for any future forum miners and time travellers that have this issue)
This is still a bug in 2023.1.8f1; as said before, toggling enable on the affected script in the editor during run-time would update transform.forward, but only on that frame. The bug also prevents transform.TransformDirection() from working properly.
I fixed it by deleting the project and cloning it again (equivalent to deleting everything but the Assets, Packages and ProjectSettings folders, and then re-importing the game). Deleting everything but these folders won’t break anything, if anyone is worried. You don’t have to mess with copying scripts into different files; that will break prefabs.