• 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 reptilebeats · Aug 18, 2012 at 01:43 AM · convert

anybody know how i would go about converting floats

i have a float of 0 to 512 and i need to convert that into 0 to 1, so 0.5 would equal 256 and so on

Comment
Add comment · Show 2
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 Kryptos · Aug 18, 2012 at 02:15 PM 0
Share

That's called proportionality. And you should have learned it in middle school.

Anyway you can find some good books about mathematics in games. Take the time to read them.

avatar image reptilebeats · Aug 18, 2012 at 08:02 PM 0
Share

like i said the only reason it wasnt working for me was because i forgot to put in localposition

1 Reply

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

Answer by Paulo-Henrique025 · Aug 18, 2012 at 01:47 AM

You just need to normalize it!

The max amount of value divided by itself is 1

512/512 = 1

Half of the value divided by the total is 0.5

256 / 512 - 0.5

To get your original value again just multiply by the max amount

0,5 * 512

Comment
Add comment · Show 5 · 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 reptilebeats · Aug 18, 2012 at 01:59 AM 0
Share

i tried this a $$anonymous$$ute ago but it wasnt responding very well, i have a slider which moves from 0 to 512 along the x axis in localposition.

i need this to be converted into a smooth motion....

ignore that i worked it out i forgot to put localposition in there, i thought i was doing it right, to tired need some sleep

avatar image Bunny83 · Aug 18, 2012 at 02:06 AM 0
Share

That's all right, but keep in $$anonymous$$d that a maximum number of 512 means there are 513 possible values since 0 is also a value.

Usually if you have a "9 bit" - number it's range goes from 0 to 511 which are 512 values. Since you have to divide by the max value it would be 511 in this case.

I'm not sure where the 512 come from, but for example if you have a texture 512x512 the highest pixel index is 511 since the index starts at 0.

Since the question doesn't give that information we can't say much more about it.

avatar image Paulo-Henrique025 · Aug 18, 2012 at 02:24 AM 0
Share

Thanks @Bunny83, missed that 0!

avatar image Bunny83 · Aug 18, 2012 at 09:08 PM 0
Share

No, everything is right ;) If his max value is 512 it's fine that way. If i see power of two numbers i immediately think of integer values (whole numbers). When reading the question again it seems he has a float value between 0 and 512.

Anyway you have to divide by the maxvalue in any case.

avatar image reptilebeats · Aug 18, 2012 at 09:27 PM 0
Share

yh i suppose 512 is a bit misleading as most would presume i am talking about pixels

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

The Unity move - converting application from C++ to C# 3 Answers

software that makes scripts for you 6 Answers

Help...convert C# to Js ??? 3 Answers

Exported SWF no longer loads 1 Answer

error BCE0022: Cannot convert error, please help 3 Answers


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