• 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 /
  • Help Room /
avatar image
0
Question by Leoo · Dec 17, 2015 at 12:51 AM · scripting problemrotation axisdaycycle

Sun Rotation to Hour?

Hey guys!,

What would you do if u wanted to get a 24h float or int from a transform.Rotation.x ???

I got my sun rotating but need to transpose that actual rotation on the x, to an Hour variable...

Simple math i know? cant figure it out.

Rotation / 360f / 24h ?

Ty!

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
0

Answer by ZefanS · Dec 17, 2015 at 01:59 AM

As long as the sun is only rotating about a single axis (the x axis for instance) this will work. There are 24 hours in a day and 360 degrees in a circle. Assuming that midnight is when the sun is pointing straight up (away from the world) and noon is when it is pointing straight down (towards the world), we have that 0 hours corresponds to 0 degrees (0 being straight up) and 12 hours corresponds to 180 degrees. The math itself is then quite simple; you were almost there:

Hour = rotation/360 * 24

Or in Unityscript:

 hour = transform.eulerAngles.x / 360.0f * 24.0f;

Just make sure to check that 0 degrees does in fact mean that the sun is pointing straight up. If not, you'll need to adjust the calculation.

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

36 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

Related Questions

Camera self rotation script problem 1 Answer

Player rotation always resets. 0 Answers

Problems with limiting angles 1 Answer

Why won't my model rotate up on X axis? 1 Answer

Attaching Light lerp to in-game clock 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges