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 Wedny · May 05, 2013 at 05:57 AM · movecoordinatesboxfloatingpoint

Box doesn't move to the position as I expect

Originally, I want to simplily move a box whose position just changes like (0,0,0)->(0,0,-1)->(0,0,-2), etc. In order to move it more realistic, I use a counter set as 50 and move the box (0,0,-0.02) and print the box's position every time FixedUpdate() called. The psuedo-code is as follows:


 function FixedUpdate () {
         if(can_move)
         {
 ……//other code
                 }
                 if(count < 50)
                 {
                         Box_position += (dir/50);
 Debug.Log(count+"box position now:“+Box_position.ToString("f8)));
                         count ++;
                 }
                 else
                  {         
                          Box_position = Box_old_position + dir;
                         
 ……//other code
                 }
         }
 }



The variant "dir" actually equals to (0,0,-1), so "dir/50" to (0,0,-0.02). The output image is as follows:


alt text


As we can see from the third to fifth figures after the decimal point in the image, it changed from "000" to "999" and then to "998"(not displayed in this image). Till now the box still move normally as I expected. However, after three times' move(50*3 for counter variant), the box's position suddenly changes abnormally when the counter is 42 in the fourth move like the image as follow


alt text


It suddenly changes from "998" to "001" to "007" and then to more big numbers in a "fast speed". In addition, the x-axis coordinates also changes abnormally because the dir's x-axis coordinates is 0.


I dont want to believe this is the Unity's problem, so can anyone tell me why?

unity3d_5.png (53.1 kB)
unity3d_6.png (57.4 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 05, 2013 at 06:07 AM

Floating point numbers are imprecise. They are an approximation of real numbers and suffer from rounding errors. Given the significance of the digits you highlight, there is no practical difference between the positions used and the "perfect" position for most applications. For the most part, this is not a Unity issue. This problem occurs with any application that uses floating point numbers. The only Unity issue here is that Unity elected to go with the less precise 'float' values rather than the more precise 'double' values (for valid technical reasons).

https://en.wikipedia.org/wiki/Floating_point

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 Wedny · May 05, 2013 at 06:27 AM 0
Share

yeah i know the floating point number are imprecies. and if it still gone from "000" to "999" to "998" in the fourth movement as the former three times, i think it will have no problems here. But it didnt happen as I expected in the fourth movement as the former three times, that's the problem.


As a result, in the former three times, the box's destination is always right as I expect for my assignment code


  else
 {
 Box_position = Box_old_position + dir;
  
 ……//other code
 }



But in the fourth movement, as I tested, after 50 times "short" movement and the last assignment for box's position in the above code, the box's position still have a litte floating-point change which I dont know how it happens because I dont have any other code to change the box's position except the above code in FixedUpdate(). This problem troubles me the most.

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

12 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

Related Questions

A node in a childnode? 1 Answer

can i download unity 3d to a flashdrive and then move it to a computer? 1 Answer

How to move BoxCollider2D so it covers a line renderer? 0 Answers

Making Character Stand? 1 Answer

Acceleration and deceleration systems 0 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