Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 douglasg14b · Mar 22, 2015 at 01:47 AM · rotationuiquaternion

Object rotation in code is different than it is in game?

I'm trying to provide a unit with a floating health bar. To keep the health bar horizontal while it is the child of that object, i subtract the objects rotation.eulerAngles.z from 360. This gives me the appropriate numbers to keep the health bar rotated in such a way that it is always horizontal. It was not working, I kept getting the inverse rotation for some reason. I did some debugging and the numbers showing up in the code where different than the ones showing up in game. I even eliminated the math and just set the rotation with a constant.

alt text alt text

No matter what the rotation is set to in the code it seems to be set to the inverse of the difference of 360 minus that rotation in game.

If I set the rotation to (0,0,350) in code, in game it's (0,0,340). 360 - 350 = 10. The inverse rotation of 10 is 340.

If I set the rotation to (0,0,270) in code, in game it's (0,0,180). 360 - 270 = 90. The Inverse rotation of 90 is 180.

What is going on here, and how do I fix it? I'm completely baffled.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ProtoTerminator · Mar 22, 2015 at 02:12 AM

You're setting world rotation, while the inspector shows local rotation. To set local rotation, use transform.localRotation.

Comment
Add comment · Show 1 · Share
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
avatar image douglasg14b · Mar 22, 2015 at 03:29 AM 0
Share

Wow, such a rookie mistake. Thanks a ton!

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

22 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

Related Questions

How to adjust rotation of map icon with a gameObject.transform.rotation 0 Answers

Why Is Rotation Different For RectTransform? 0 Answers

Trying to rotate a 2D image over time to a specific angle, but it's rotating its Y value every time 1 Answer

Rotate rect transform ui by touch 0 Answers

Why does only the first of sequential quaternion operations work? 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