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 BritishGuy · Jan 25, 2015 at 01:52 AM · convertspacefastunitsmeters

m/s "Meters" convert to au/s "Astronomical Units"

Hello,

How would i go about converting units of measurements from m/s to au/s

So far my speed measurements are in meters a second "m/s" but the numbers become overwhelming at high speeds, light-speed, hyper-speed and so on.

So as soon as i get to the speed of 1,495,978,707 meters it then start to convert units? Thanks.

1,495,978,707 m/s = 0.01 au/s

14,959,787,070 m/s = 0.1 au/s

149,597,870,700 m/s = 1.0 au/s

Comment
Add comment · Show 4
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 BritishGuy · Jan 25, 2015 at 02:55 AM 0
Share

I am sure there is a better way than what i am trying to do here, Any suggestions?

 void Update(){
 
         au = velocity/149597870700;
 
         if(au <= 0.01f)
         {
         shipVelocity.text = "Velocity:  " + velocity + " m/s";
         }
 
         if(au >= 0.0099f){
         shipVelocity.text = "Velocity:  " + au + " au/s";
         }
     }
avatar image Unitraxx · Jan 25, 2015 at 03:12 AM 1
Share

Uhm this seems pretty ok? Are you worried about the division? If you would like to sacrifice precision, you can use bit shift to obtain a faster division. (I suggest shifting 30 bits to the right for approximating a division by 1495978707.)

avatar image NoseKills · Jan 25, 2015 at 09:48 AM 2
Share

As a concept there's nothing wrong with what you are doing. But the condition should just be an if-else. You don't need 2 if's to check if a number is greater than X. If the value is under 0.01au, you show speed in m/s. In all other cases you want au, right?

          if(au <= 0.01f)
          {
              shipVelocity.text = "Velocity:  " + velocity + " m/s";
          }
          else
          {
              shipVelocity.text = "Velocity:  " + au + " au/s";
          }

You could also micro optimize by calculating the threshold speed in m/s in the beginning of the game and then calculating au only if you need to show it. But there's no need for that unless you have hundreds of objects calculating this in Update()

avatar image BritishGuy · Jan 25, 2015 at 12:48 PM 0
Share

Spot on, thanks for the suggestions they really do help allot,

For the if statements, I originally had 3 speeds m/s, $$anonymous$$/s, au/s so it was if, else if, else, but thanks for pointing that out i didn't notice it until i read your comment.

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

20 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

Related Questions

Convert Canvas space to World coordinates 2 Answers

Space unit size 2 Answers

Convert Units to Pixels and back 1 Answer

How to convert pixels to Unity units? 3 Answers

How to calculate distance in meters? 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