If I have a character in my 2D game that has its rotation set in the inspector like so:
![alt text][1]
If I do this as soon as my scene loads before moving my character:
Debug.Log(transform.rotation);
I get the output "**(0.0, 1.0, 0.0, 0.0)**"
But if I then flip the direction the character is facing by doing this:
transform.Rotate(0f, 180f, 0f, Space.World);
Now I get the output "**(0.0, 0.0, 0.0, 1.0)**"
So far so good, the character was rotated as expected and everything works as it should.
But this is where things get confusing - if I change the direction the character is facing again at runtime by running that same transform.Rotate code again, now the debug output shows
"**(0.0, -1.0, 0.0, 0.0)**"
Why don't I end up with the same values I started with after doing two 180 rotations?
Despite these differing values, the character would still start facing the direction I expected (and would flip their direction correctly when I called transform.Rotate). So this all seemed fine... until I started trying to fire projectiles from the character. The projectiles are instantiated by the character like this:
Transform launchLocation; ... Instantiate(projectileInfo.prefab, launchLocation.position, launchLocation.rotation)
If I fired a projectile without first flipping the character at least once with "transform.Rotate", all sorts of weird stuff happened with the projectile collision (started rapidly spinning as soon as it spawned etc).
I've since "fixed" that issue by changing my Instantiate call to use Quaternion.identity to avoid any rotation :
Instantiate(projectileInfo.prefab, launchLocation.position, Quaternion.identity)
But regardless of that, I'm still really confused why I get different values for the object's rotation if its set in the inspector vs calling transform.Rotate. Is it good practice to not set rotation with the inspector and instead do it purely in code? Seems like that would be a bit awkward for setting up scenes accurately though. [1]: /storage/temp/145994-rot.jpg
![alt text][1]
If I do this as soon as my scene loads before moving my character:
Debug.Log(transform.rotation);
I get the output "**(0.0, 1.0, 0.0, 0.0)**"
But if I then flip the direction the character is facing by doing this:
transform.Rotate(0f, 180f, 0f, Space.World);
Now I get the output "**(0.0, 0.0, 0.0, 1.0)**"
So far so good, the character was rotated as expected and everything works as it should.
But this is where things get confusing - if I change the direction the character is facing again at runtime by running that same transform.Rotate code again, now the debug output shows
"**(0.0, -1.0, 0.0, 0.0)**"
Why don't I end up with the same values I started with after doing two 180 rotations?
Despite these differing values, the character would still start facing the direction I expected (and would flip their direction correctly when I called transform.Rotate). So this all seemed fine... until I started trying to fire projectiles from the character. The projectiles are instantiated by the character like this:
Transform launchLocation; ... Instantiate(projectileInfo.prefab, launchLocation.position, launchLocation.rotation)
If I fired a projectile without first flipping the character at least once with "transform.Rotate", all sorts of weird stuff happened with the projectile collision (started rapidly spinning as soon as it spawned etc).
I've since "fixed" that issue by changing my Instantiate call to use Quaternion.identity to avoid any rotation :
Instantiate(projectileInfo.prefab, launchLocation.position, Quaternion.identity)
But regardless of that, I'm still really confused why I get different values for the object's rotation if its set in the inspector vs calling transform.Rotate. Is it good practice to not set rotation with the inspector and instead do it purely in code? Seems like that would be a bit awkward for setting up scenes accurately though. [1]: /storage/temp/145994-rot.jpg