Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Chris128 · Sep 10, 2019 at 08:06 PM · rotationtransforminspectorrotatingtransform.rotate

Transform.rotate gives different result to rotation in inspector

If I have a character in my 2D game that has its rotation set in the inspector like so:

alt text


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.

rot.jpg (22.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

111 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

bone rotations changed in 4.3.2 inspector? 0 Answers

How to modify the rotation speed of an object using Transform.Rotate 3 Answers

transform.Rotate For an Certain Amount of Time 1 Answer

Resetting transform's original position and rotation after using transform.rotateAround 1 Answer

Floating-point errors while assigning transforms 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges